tips
119 tips Access and security
One command, setting or habit at a time about Access and security: what it does, the line to copy and a caveat or two.
Access and security 119
-
Verify only the downloaded files against a big checksum list, without errors for the rest.
sha256sum -c --ignore-missing SHA256SUMS -
List accounts that have not logged in for a number of days
lastlog --before 90 -
Rehearses a Let's Encrypt renewal against the staging server without saving any certificate.
certbot renew --dry-run -
Shows each certificate Certbot manages, with its domains, expiry date and file paths.
certbot certificates -
Creates a local CA and trusted certificates for localhost and test names in two commands.
mkcert -install -
Sends a chosen host name in the TLS handshake so you see that site's certificate.
openssl s_client -connect 203.0.113.10:443 -servername example.com </dev/null | openssl x509 -noout -subject -
Re-signs an existing self-signed certificate with new dates, keeping its key and extensions.
openssl x509 -in cert.pem -days 365 -signkey key.pem -out cert-new.pem -
Computes an HMAC of a file or text with a secret key, as used for webhook signatures.
printf %s hello | openssl dgst -sha256 -hmac secret -
Loads the legacy provider so OpenSSL 3 can read a .pfx made with RC2 or 3DES.
openssl pkcs12 -legacy -in old.pfx -nokeys -
Explains how a site turns HSTS off again and why that only works over HTTPS.
Strict-Transport-Security: max-age=0 -
Logs in to a registry with a password read from standard input, not typed in the command.
cat ~/my_token.txt | docker login --username myname --password-stdin -
Organizes environments into groups, so access and tags apply to all of them at once.
-
Changes a namespaced kernel setting inside a single container, without touching the host's settings.
docker run --rm --sysctl net.ipv4.ip_forward=1 alpine cat /proc/sys/net/ipv4/ip_forward -
Put contact details on the lock screen in case the Mac gets lost.
System Settings > Lock Screen > Show message when locked (on) -
Turn off a background service while the app itself stays installed.
sudo snap stop --disable lxd.daemon -
Identify the service and often the version behind each open port.
nmap -sV 192.0.2.10 -
Spot new or vanished ports by diffing a saved scan against a fresh one.
nmap -oX before.xml 192.0.2.10 -
Read what a script does and which categories it belongs to.
nmap --script-help ssh2-enum-algos -
Encode and decode base64 with one command that works the same on Linux, macOS and BSD.
echo 'aGVsbG8gd29ybGQ=' | openssl base64 -d -
Write the TLS session secrets to a file so a packet capture of that connection can be decrypted.
| openssl s_client -connect example.com:443 -servername example.com -quiet -keylogfile keys.log -
Shows which accounts are in the groups that grant sudo or root access.
getent group sudo adm docker lxd -
Find the folder OpenSSL uses for openssl.cnf and trusted certificates on this machine.
openssl version -d -
Compare the public key inside a certificate with the one derived from a private key.
openssl x509 -in site.pem -noout -pubkey | openssl sha256 -
Know that :ro on docker.sock still lets a container control Docker fully.
- /var/run/docker.sock:/var/run/docker.sock:ro -
Edit system files safely without running a whole editor as root.
sudoedit /etc/ssh/sshd_config -
See exactly which cipher suites a config string like ECDHE+AESGCM allows.
openssl ciphers -v 'ECDHE+AESGCM' -
Pin the server's public key, so even a valid certificate with another key is refused.
openssl x509 -in server.pem -pubkey -noout \ -
Disables an account completely, so key logins stop too, without deleting anything.
sudo usermod --expiredate 1 bob -
Force a TLS version range to see which versions a server accepts.
curl -sv -o /dev/null --tlsv1.2 --tls-max 1.2 https://example.com/ 2>&1 | grep 'SSL connection' -
Uses your fingerprint for sudo, in a way that survives macOS updates.
sed 's/^#auth/auth/' /etc/pam.d/sudo_local.template | sudo tee /etc/pam.d/sudo_local -
Shows who is logged in right now, from where, and what they are running.
w -
Turn a CSR into a certificate signed by a homelab CA, keeping the host names from the request.
openssl x509 -req -in nas.csr \ -
Restrict who may reach published container ports with rules Docker will not overwrite.
sudo iptables -I DOCKER-USER -i eth0 ! -s 192.0.2.0/24 -j DROP -
Use your own certificate and key to pass mutual TLS checks on an API or proxy.
curl --cert client.pem --key client.key https://api.example.com/status -
Grab every certificate a server presents, so you can inspect or verify the chain offline.
echo | openssl s_client -connect example.com:443 -servername example.com -showcerts 2>/dev/null \ -
Removes the quarantine mark that makes Gatekeeper block a downloaded tool.
xattr -d com.apple.quarantine ./tool -
Convert a .cer or .der certificate into the text PEM format Linux software expects.
openssl x509 -inform der -in cert.cer -out cert.pem -
Encrypt and decrypt a single file with a password the safer way openssl enc offers.
openssl enc -aes-256-cbc -pbkdf2 -salt -in notes.txt -out notes.txt.enc -
Prove a file came from you and was not changed, using a key pair and two commands.
openssl dgst -sha256 -sign private.pem -out backup.tar.gz.sig backup.tar.gz -
Generate a crypt style password hash for cloud-init, Ansible or a user account.
openssl passwd -6 -
Encrypt a private key file with a passphrase, or take it off for a service that cannot ask.
openssl pkey -in site.key -aes256 -out site-enc.key -
Inspect a certificate signing request and check its signature, so a typo does not cost a reissue.
openssl req -in site.csr -noout -text -verify -
Enables the firewall without the interactive question, for setup scripts.
ufw --force enable -
See if a server sends a stapled OCSP response with its certificate, and what it says.
echo | openssl s_client -connect example.com:443 -servername example.com -status 2>/dev/null \ -
Run a command as a service account from a root script, without su or sudo prompts.
runuser -u www-data -- php /var/www/app/occ status -
Lists every account in /etc/passwd that has root's user ID.
awk -F: '($3 == 0) {print $1}' /etc/passwd -
Decode the hex error codes that OpenSSL based programs print in logs.
openssl errstr 0A000086 -
Benchmark AES and other algorithms on a NAS, Pi or VPS before you pick a cipher or VPN.
openssl speed -evp aes-256-gcm -
See all certificates in a chain or CA bundle, since x509 only reads the first one.
openssl storeutl -noout -certs fullchain.pem -
Run a tiny TLS server to test a certificate, a client or a firewall rule.
openssl s_server -accept 8443 -cert cert.pem -key key.pem -www -
Make a CSR with several Subject Alternative Names in one line, without a config file.
openssl req -new -key site.key \ -
Check the protocol a server picks in the TLS handshake, such as h2 or http/1.1.
echo | openssl s_client -connect example.com:443 -servername example.com -alpn h2 2>/dev/null | grep -i alpn -
Treat membership of the docker group like sudo without a password.
sudo usermod -aG docker "$USER" -
Records the terminal output of sudo sessions so you can replay them later.
sudo visudo -f /etc/sudoers.d/iolog -
Keep an HSTS cache file so curl upgrades plain http URLs for sites that asked for it.
curl --hsts ~/.curl-hsts https://example.com/ -
Prints for each account whether its password is set, locked or empty.
sudo passwd -S -a -
Protects passwords and keys you type in Terminal from keyloggers and snooping apps.
Terminal (menu bar) > Secure Keyboard Entry -
Split a PKCS#12 bundle from Windows or a NAS export into PEM files for Linux software.
openssl pkcs12 -in site.pfx -nokeys -clcerts -out cert.pem -
See every certificate in the chain, with subject, issuer and dates, from one curl command.
curl -s -o /dev/null -w '%{num_certs}\n%{certs}' https://example.com/ | grep -E '^[0-9]|Subject:|Issuer:|Expire' -
Make s_client fail on a wrong host name or untrusted chain instead of just printing a warning.
echo | openssl s_client -connect example.com:443 -servername example.com \ -
Generate any type of private key with the modern genpkey command instead of genrsa.
openssl genpkey -algorithm ed25519 -out ed.key -
Removes every Linux capability from a container so you only add back what the app really needs.
docker run -d --name web --cap-drop ALL --cap-add NET_BIND_SERVICE -p 8080:80 nginx -
Blocks processes inside a container from gaining extra privileges through su, sudo or setuid binaries.
docker run --rm -it --security-opt no-new-privileges ubuntu bash -
Gives a container access to one host device, like a USB stick, without using privileged mode.
docker run -d --name zigbee --device=/dev/ttyUSB0:/dev/ttyUSB0 example/zigbee:1.0 -
Shows the password and account expiry settings of a Linux user.
chage -l <user> -
Clears sudo's cached password so the next command asks for it again.
sudo -k -
Limits curl and its redirects to HTTPS so a link can never downgrade to plain HTTP.
curl --proto =https --proto-redir =https -L -o install.sh https://example.com/install.sh -
Lets curl take the login for a host from a locked-down .netrc file, so no password shows in the command.
password secret -
Shows the failed logins of a user and clears the records that lock the account.
sudo faillock --user alice -
Checks sudoers and its included files for syntax errors and returns an exit code.
sudo visudo -c && echo sudoers ok -
Checks whether a password is in known breaches by sending only 5 characters of its SHA-1 hash.
curl -s "https://api.pwnedpasswords.com/range/${H:0:5}" | grep -i "${H:5:35}" -
Saves the LUKS header and keyslots to a file, so a damaged header does not mean lost data.
sudo cryptsetup luksHeaderBackup /dev/sdb1 --header-backup-file /root/sdb1-header.img -
Lists every TLS protocol and cipher a server accepts and grades the weakest one from A to F.
nmap --script ssl-enum-ciphers -p 443 proxy.example.com -
Opens a STARTTLS session to a mail server and shows the certificate and TLS details.
openssl s_client -starttls smtp -connect mail.example.com:587 -servername mail.example.com -brief -
Replaces your FileVault recovery key with a new one when the old key may be exposed.
sudo fdesetup changerecovery -personal -
Checks from Terminal whether FileVault disk encryption is on and a recovery key exists.
fdesetup status -
Shows which saved passwords are weak, reused or found in a data leak.
Passwords > Security -
Stores two-factor codes for your accounts in the Mac Passwords app and fills them in.
Passwords > select the account > Edit > Set Up Code -
Checks whether a Mac is enrolled in device management and lists its installed profiles.
profiles status -type enrollment -
Makes new downloaded apps ask before the Mac firewall lets incoming connections in.
/usr/libexec/ApplicationFirewall/socketfilterfw --getallowsigned -
Asks Gatekeeper whether an app or installer would be allowed, without opening it.
spctl --assess --verbose /Applications/SomeApp.app -
Clears an app's saved privacy permission so macOS asks you again next time.
tccutil reset Camera com.example.app -
Sets when an Apple silicon MacBook asks before it lets a USB or Thunderbolt accessory connect.
System Settings > Privacy & Security > Accessories > Allow accessories to connect -
Shows the developer and certificate chain behind an app's code signature.
codesign -dv --verbose=4 /Applications/SomeApp.app -
Lets a Portainer agent accept any Portainer server that knows a shared secret, instead of only the first.
docker run -d -p 9001:9001 --name portainer_agent --restart=always \ -
Keeps fail2ban from banning addresses on your own LAN or tailnet.
ignoreip = 127.0.0.1/8 ::1 192.168.1.0/24 100.64.0.0/10 -
Finds and backs up the certificate that lets you revoke a lost or leaked GPG key.
ls ~/.gnupg/openpgp-revocs.d/ -
Combines a private key, certificate and chain into one password-protected .pfx file.
openssl pkcs12 -export -inkey site.key -in site.pem \ -
Checks whether a certificate and its intermediates form a valid chain before you deploy them.
openssl verify -show_chain -CAfile root.pem -untrusted intermediate.pem cert.pem -
Caps how many processes a container may start, so a runaway or fork bomb stays inside it.
docker run -d --pids-limit 200 --name web nginx -
Prints random bytes from a secure generator, encoded as base64 or hex, for use as a password or key.
openssl rand -base64 32 -
Creates a named context for a remote Docker host, so docker commands run there through SSH.
docker context create remote --docker "host=ssh://[email protected]" -
Prints every table, chain and rule that nftables currently has loaded in the kernel.
sudo nft list ruleset -
Encrypts a file with GnuPG, either with a passphrase or for someone's public key.
gpg --symmetric --armor --output secret.txt.asc secret.txt -
Creates a private key and a self-signed certificate with a subjectAltName, for testing HTTPS locally.
openssl req -x509 -newkey rsa:2048 -days 365 \ -
Prints the SHA-256 fingerprint of a PEM certificate, for comparing with a value you trust.
openssl x509 -fingerprint -sha256 -noout -in cert.pem -
Disables a user's password login on Linux, and what else is needed to really block the account.
sudo passwd -l olduser -
Lists the password aging and expiry details of a user account.
chage -l jordi -
Verifies that a downloaded file matches its detached signature and was signed by the key you expect.
gpg --import project-signing-key.asc -
Shows the log of bad login attempts that Linux keeps in /var/log/btmp.
sudo lastb | head -n 20 -
Fetches a Let's Encrypt certificate for your machine's tailnet name, so a service can use HTTPS.
sudo tailscale cert machine.your-tailnet.ts.net -
Prints the start and end date of a website's TLS certificate from the terminal.
echo | openssl s_client -connect example.com:443 -servername example.com 2>/dev/null | openssl x509 -noout -dates -
Turns off Portainer's plain HTTP port so the web UI is only served over HTTPS.
docker run -d ... portainer/portainer-ce:lts --http-disabled -
Lets a team see containers started outside Portainer through a label, instead of administrators only.
docker run -d --label io.portainer.accesscontrol.teams=devs nginx -
Logs Portainer in to Docker Hub so it can pull private images and many images.
-
Resets the Portainer admin password by running a helper container against the data volume.
docker stop portainer -
Sets the first admin password from a file when Portainer starts, so you skip the setup page.
docker run -d -p 9443:9443 --name portainer \ -
Lists files that run with their owner's privileges so unexpected ones stand out.
sudo find / -xdev -type f -perm -4000 2>/dev/null | sort > suid-today.txt -
Shows which commands a user may run with sudo and under which conditions.
sudo -l -
Forces one TLS version in the handshake to see whether a server still accepts it.
openssl s_client -connect example.com:443 -servername example.com -tls1_1 </dev/null -
Tests whether a certificate file expires within a chosen time and signals it with the exit code.
openssl x509 -in /etc/ssl/site/fullchain.pem -noout -checkend 1209600 -
Lists open ports and the programs behind them, the starting point for an exposure review.
sudo ss -tulpn -
Checks how many log lines a fail2ban filter matches before any ban is created.
sudo fail2ban-regex /var/log/auth.log sshd -
Shows the matches and banned addresses of a fail2ban jail, and how to lift a ban.
sudo fail2ban-client status sshd -
Lists the sandbox permissions of a snap and whether each is connected.
snap connections firefox -
Opens a port only to one source network instead of to everyone.
sudo ufw allow from 192.168.1.0/24 to any port 5432 proto tcp -
Passes secrets to curl through stdin instead of visible command-line arguments.
printf 'header = "Authorization: Bearer %s"\n' "$API_TOKEN" | curl -K - https://api.example.com/me -
Verifies a server against your own certificate authority instead of skipping verification.
curl --cacert /etc/ssl/homelab-ca.pem https://nas.lan:8443/ -
Makes curl ask for the password so it never appears in history or the process list.
curl -u alice https://example.com/private/
Nothing in this filter yet.