tips
79 tips Security
One command, setting or habit at a time about Security: what it does, the line to copy and a caveat or two.
Access and security 26
-
Creates a local CA and trusted certificates for localhost and test names in two commands.
mkcert -install -
Explains how a site turns HSTS off again and why that only works over HTTPS.
Strict-Transport-Security: max-age=0 -
Shows which accounts are in the groups that grant sudo or root access.
getent group sudo adm docker lxd -
Disables an account completely, so key logins stop too, without deleting anything.
sudo usermod --expiredate 1 bob -
Shows who is logged in right now, from where, and what they are running.
w -
Lists every account in /etc/passwd that has root's user ID.
awk -F: '($3 == 0) {print $1}' /etc/passwd -
Records the terminal output of sudo sessions so you can replay them later.
sudo visudo -f /etc/sudoers.d/iolog -
Prints for each account whether its password is set, locked or empty.
sudo passwd -S -a -
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 -
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 -
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 -
Shows the developer and certificate chain behind an app's code signature.
codesign -dv --verbose=4 /Applications/SomeApp.app -
Finds and backs up the certificate that lets you revoke a lost or leaked GPG key.
ls ~/.gnupg/openpgp-revocs.d/ -
Encrypts a file with GnuPG, either with a passphrase or for someone's public key.
gpg --symmetric --armor --output secret.txt.asc secret.txt -
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
Hardening 25
-
Stops programs from being run directly out of the shared memory folder.
findmnt -no OPTIONS /dev/shm -
Makes /home, /root and /run/user empty and unreachable for one service.
sudo systemctl edit myapp.service -
Builds a database of file checksums and later reports every file that changed.
sudo apt install aide -
Stops the server from changing its routes because of ICMP redirect messages.
sysctl -a 2>/dev/null | grep -E 'accept_redirects|send_redirects' -
Hides other users' processes and their command lines from normal accounts.
sudo mount -o remount,hidepid=2 /proc -
Makes passwd refuse short or dictionary passwords for local accounts.
sudo apt install libpam-pwquality -
Limits which IP addresses a single service may talk to, in both directions.
sudo systemctl edit myapp.service -
Checks the account files for broken lines without changing a thing.
sudo pwck -r -
Scans Dockerfiles and other config files for risky settings like running as root.
trivy config . -
Ends an interactive bash session after a set time without input.
echo 'readonly TMOUT=900; export TMOUT' | sudo tee /etc/profile.d/tmout.sh -
Stops unprivileged users from reading the kernel ring buffer with dmesg.
sysctl kernel.dmesg_restrict kernel.kptr_restrict -
Switches one AppArmor profile to logging mode, so you can see what it would block.
sudo aa-complain /usr/sbin/nginx -
Lists every administrator account of a WordPress site with only the columns you pick.
wp user list --role=administrator --fields=ID,user_login,user_email,user_registered -
Ends every login session of one WordPress account so old logins stop working.
wp user session destroy admin --all -
Scans a container image and shows only serious vulnerabilities that already have a fix.
trivy image example/app:1.2 -
Rates the firmware protections of a Linux machine from HSI:0 to HSI:5 and explains each failed test.
fwupdmgr security -
Makes an SSH key work only from the IP addresses or networks you list.
from="192.168.1.0/24" ssh-ed25519 AAAAC3Nza... laptop -
Runs a rootkit and suspicious-file scan without stopping to ask for a keypress.
sudo rkhunter --check --sk -
Replaces the keys and salts in wp-config.php so every existing WordPress login session becomes invalid.
wp config shuffle-salts -
Stops anyone from installing or updating plugins and themes in the admin, so a stolen login can do less.
define( 'DISALLOW_FILE_MODS', true ); -
Audits a Linux host read-only and lists warnings and suggestions with a hardening index.
sudo lynis audit system -
Disables SSH password logins in a separate file that package updates leave alone.
sudo sshd -t && sudo systemctl reload ssh -
Lists the fingerprint and type of every key allowed to log in to an account.
ssh-keygen -lf ~/.ssh/authorized_keys -
Validates the sshd configuration first and reloads only when the check succeeds.
sudo sshd -t && sudo systemctl reload ssh -
Prints the complete effective sshd configuration so you can see what is actually enabled.
sudo sshd -T | grep -Ei 'permitrootlogin|passwordauthentication|pubkeyauthentication|allowusers'
Nginx Proxy Manager 8
-
Explains what the HSTS switches in NPM send and why they stick for two years.
Strict-Transport-Security: max-age=63072000; preload -
Limits a proxy host to addresses you list, without asking for any password.
allow 192.0.2.0/24; -
Explains why a password on a proxy host breaks apps that have their own login.
-
Makes Nginx Proxy Manager read its database password from a file instead of the compose file.
environment: -
Allows Nginx Proxy Manager hosts to be shown in iframes from the same origin.
environment: -
Limits how many requests per second one client can send to your Nginx Proxy Manager hosts.
limit_req_zone $binary_remote_addr zone=npmlimit:10m rate=10r/s; -
Changes the port of the Nginx Proxy Manager admin page from 81 to one you choose.
ports: -
Prints the hostnames, issuer and dates of a certificate file in one line of commands.
openssl x509 -in fullchain.pem -noout -subject -issuer -dates -ext subjectAltName
System 3
-
Regain WebGUI access from the console when DNS is down and SSL is set to Strict.
use_ssl no -
Keep the boot device share off the network so nobody on your LAN can change it.
Yes visible and reachable -
Keeps your SSH key login working after Unraid restarts, by storing the key on the flash drive.
nano /boot/config/ssh/root/authorized_keys
Apps and containers 2
-
Lists every running container together with its privileged flag.
docker ps -q | xargs docker inspect -f '{{.Name}} privileged={{.HostConfig.Privileged}}' -
Spot deprecated, incompatible or blacklisted apps on your server, not just updates.
Inspecting packages 2
-
Counts your installed packages by where their security updates come from.
pro security-status -
Shows which installed package files on Debian or Ubuntu were modified since install.
sudo debsums -c
Network and DNS 2
-
Open a saved packet capture in tcpdump and filter it with the usual expressions
tcpdump -nn -r capture.pcap port 53 -
Scans all TCP ports of your own server from outside and lists only the open ones.
nmap -Pn -p- --open 192.168.1.10
Compose 1
-
Reads an env file without interpolation, so dollar signs and quotes arrive unchanged.
format: raw
Containers 1
-
Makes a container's filesystem read-only, with writable memory-backed folders only where you allow them.
docker run -d --read-only \
Filtering 1
-
Filters the journal by syslog facility, for example login and privilege messages only.
journalctl --facility=auth,authpriv --since today
Headers and timing 1
-
Controls whether the browser sends the Referer header, and how much of the address it contains.
Referrer-Policy: strict-origin-when-cross-origin
Hooks 1
-
Blocks Claude Code from editing protected files by running a script that exits with code 2.
exit 2
Keyboard and desktop 1
-
Locks your Mac screen instantly with one shortcut, while your apps keep running.
Control-Command-Q lock your screen
Routing 1
-
Closes the connection for requests whose host name matches none of your sites.
server {
SSH 1
-
Creates an SSH key that needs your hardware security key to be used.
ssh-keygen -t ed25519-sk -C "laptop-key"
Settings and access 1
-
Turns on Apple's extreme protection mode and lets you exclude single websites in Safari.
WP-CLI 1
-
Lists the users with super admin capabilities on a WordPress multisite install.
wp super-admin list
Windows 1
-
Starts one program with administrator rights from a normal PowerShell window.
Start-Process -FilePath "powershell" -Verb RunAs
Nothing in this filter yet.