Security & SSH
SSH ignores your key if ~/.ssh on the server is writable by others.
~/.ssh must be 700 and authorized_keys 600, or sshd ignores the key.
chmod 700 ~/.ssh && chmod 600 ~/.ssh/authorized_keysShort, practical things every sysadmin, developer and DevOps engineer should know, each with a command to try and a full explanation. A new tip of the day, every day.
Security & SSH
~/.ssh must be 700 and authorized_keys 600, or sshd ignores the key.
chmod 700 ~/.ssh && chmod 600 ~/.ssh/authorized_keysFiles & directories
vim -es -c "cmd" -c "wq" file runs Vim commands on a file non-interactively.
vim -es -c "%s/old/new/g" -c wq fileSystem & services
Escape % as % in crontab commands, or put the command in a script.
crontab -eShell & terminal
Use cmd | sudo tee file (or tee -a to append) to write root-owned files.
echo text | sudo tee -a /etc/fileSystem & services
Exit status = 128 + signal number: 143 is SIGTERM, 137 is SIGKILL (often the OOM killer).
echo $?Files & directories
Use chmod -R u=rwX,go=rX to get 755 folders and 644 files in one command.
chmod -R u=rwX,go=rX dirSystem & services
systemd 259 dropped runlevel/telinit and the runlevelN.target aliases. Use systemctl get-default / isolate multi-user.target.
systemctl get-defaultSystem & services
blame lists slow services; critical-chain shows the ones the boot actually waited for (@ = ready at, + = took).
systemd-analyze critical-chainWindows
Task Manager → Startup apps → "Last BIOS time" shows how long the firmware (including POST) took before Windows started.
Shell & terminal
printf "Hi" | basenc --base2msbf shows 0100100001101001: each character as 8 bits. Add -d to decode.
printf "Hi" | basenc --base2msbfWindows
Settings → System → Display → Graphics: pick an app, then Power saving (integrated) or High performance (dedicated).
System & services
Check the "Kernel driver in use" line: nvidia, nouveau, amdgpu, i915 or xe. Seeing nouveau after installing NVIDIA? Reboot.
lspci -k | grep -EA3 'VGA|3D|Display'System & services
Check free slots and whether two sticks sit on different channels (A and B) for dual channel, without opening the case.
sudo dmidecode -t 17 | grep -E 'Size|Locator'Disks & storage
In the ROTA column, 1 means a rotating hard disk and 0 means an SSD or flash drive. VMs report what the hypervisor says.
lsblk -d -o NAME,ROTA,SIZE,MODELWeb servers
Turn it off with the wp_enable_random_content_redirect filter if your page cache could serve one redirect to everyone.
curl -sI https://example.com/random/DevOps & cloud
Each Docker Desktop VMM has its own disk: push images and back up volumes before switching to Docker VMM.
docker save -o images.tar myapp:latestProgramming
Replace app.options('*') with app.options('/{*splat}') in Express 5, or rely on app.use(cors()).
app.options('/{*splat}', cors());Web servers
CORS only controls reading responses; protect state-changing endpoints with auth and CSRF tokens.
curl -s -D - -H "Origin: https://evil.com" URLDevOps & cloud
Copy the bucket name from the Firebase console: new projects use .firebasestorage.app.
gcloud storage buckets listDevOps & cloud
Wrap S3 CORS rules in {"CORSRules": [...]} for aws s3api put-bucket-cors.
aws s3api put-bucket-cors --bucket my-assets --cors-configuration file://cors.jsonWeb servers
Use Header unset before Header always set when proxying an app that sends its own CORS headers.
Header unset Access-Control-Allow-OriginWeb servers
Use map $http_origin to echo allowed origins; never list several in one header.
add_header Access-Control-Allow-Origin $cors_origin always;Disks & storage
cmp -n $(stat -c%s file.iso) file.iso /dev/sdX after dd; no output means identical.
sudo cmp -n $(stat -c%s file.iso) file.iso /dev/sdbDisks & storage
mkfs.ext4 -n lists backup superblocks; e2fsck -b 32768 repairs from one.
sudo e2fsck -fy -b 32768 /dev/sdb1Web servers
chmod 2775 storage/logs (group www-data) plus permission 0664 in config/logging.php.
sudo chmod 2775 storage/logsDisks & storage
cd out of the mount point, then use fuser -vm to find what still holds it.
sudo fuser -vm /mnt/dataDisks & storage
Run sudo findmnt --verify after every fstab edit, then mount -a, before rebooting.
sudo findmnt --verifyDisks & storage
Always pass -F 32 to mkfs.vfat when a device needs FAT32, then confirm with blkid.
sudo mkfs.vfat -F 32 -n MYUSB /dev/sdb1AI & LLMs
Check /v1/models monthly for shutdown_date and alert on any model ID your code or settings still use.
curl -s https://api.openai.com/v1/modelsDevOps & cloud
Kubernetes 1.35+ needs cgroup v2 nodes; cgroup2fs means you are ready, tmpfs means cgroup v1.
stat -fc %T /sys/fs/cgroup/System & services
RAM is sold in binary units (1 GB = 1024³ bytes) but disks in decimal, so a 1 TB SSD shows as ~931 GB.
free -hProgramming
Ubuntu's openjdk-21/25 JRE packages lack ct.sym, so Maven builds with <release> fail with "release version N not supported" until you install the -jdk package.
sudo apt install openjdk-21-jdk-headlessSystem & services
Cron on Ubuntu/Debian always uses the system time zone; CRON_TZ only works with cronie (RHEL family).
timedatectlSystem & services
Read /sys/class/dmi/id/product_name to get the board name, and include it in bug reports for Linux on the Deck.
cat /sys/class/dmi/id/product_nameSystem & services
Enable boot.loader.systemd-boot.bootCounting so a bad generation is marked failed and the previous one boots.
sudo nixos-rebuild switch --rollbackSecurity & SSH
Nested virtualization widens the guest-to-host attack surface. Turn it off if no VM needs to run its own VMs.
cat /sys/module/kvm_amd/parameters/nestedWindows
Right-click the title bar, choose Change Settings, edit Connection > SSH > Tunnels and click Apply.
plink -N -L 5050:127.0.0.1:5432 user@serverSystem & services
Mint now ships one release a year with no point releases. Mint 27 is based on Ubuntu 26.04; 22.3 is supported to April 2029.
AI & LLMs
Carbon and Argon cost twice as much from 1 Dec. Recheck budgets, or switch to Neon or Hydrogen for cheaper calls.
grepSystem & services
Press F4 in htop and type nginx|php-fpm, or start it with htop -F to filter from the command line.
htop -F 'nginx|php-fpm'Web servers
Add limit_req_status 429; so rate-limited clients get 429 Too Many Requests instead of a misleading 503.
AI & LLMs
Sending "medium" to Qwen4-Max gives you high effort. Set reasoning_effort to low for cheap, fast calls.
Networking
Check for MPTCP listeners with ss -Mltn; turn it off per service with GODEBUG=multipathtcp=0.
ss -MltnPackages
Moving to Azure Linux 4? Replace tdnf with dnf in Dockerfiles, cloud-init and CI before you deploy.
grep -rn tdnf .System & services
Building 7.4+ with Binder? Run make LLVM=1 rustavailable first to confirm the Rust toolchain is ready.
make LLVM=1 rustavailableSecurity & SSH
After updating to 9.9, re-enable it with authselect enable-feature with-group-merging if you mix local and SSSD groups.
sudo authselect enable-feature with-group-mergingSystem & services
Pick the mode in Agama before installing Leap 16.1; switching later means a reinstall.
sudo transactional-update pkg install htopSystem & services
On SLES 16.1, read /proc/pressure/{cpu,memory,io} for real overload signals; psi=0 disables it.
cat /proc/pressure/cpuPackages
To check whether Ubuntu's PHP is patched, compare the package revision (dpkg -l), not the php -v version.
dpkg -l 'php8*' | awk '/^ii/ {print $2, $3}'Web servers
Build HTTPS redirects with %{SERVER_NAME}, not %{HTTP_HOST}, or use a fixed hostname.
curl -sI -H "Host: example.com:80" http://127.0.0.1/ | grep -i locationWeb servers
End the target of Redirect / with a slash: Redirect permanent / https://example.com/
curl -sI http://example.com/blog/post | grep -i locationWeb servers
Use Header always set for HSTS and other security headers; add Header unset to drop a proxied backend's copy.
curl -sI https://example.com/nope | grep -i strictWeb servers
Repeat security headers in each location with its own add_header, or use add_header_inherit merge on Nginx 1.29.3+.
grep -rn 'add_header' /etc/nginx/Web servers
Set ssl_session_cache and ssl_session_timeout in the http context, not only per site.
openssl s_client -connect example.com:443 -tls1_2 -reconnect -no_ticketProgramming
Benchmark big analytical queries after upgrading; set jit = on if they got slower.
SHOW jit;DevOps & cloud
Run claude interactively in the folder once and accept the trust prompt; deny rules apply either way.
cd ~/server-ops && claudeWeb servers
str_replace(' ', '-', ?) returns a function that slugs any string, ready for array_map() or the |> pipe.
Web servers
After upgrading, test cross-site POST callbacks (payments, SSO): they may need SameSite=None with Secure.
php -i | grep session.cookie_samesiteWeb servers
Replace max($min, min($max, $v)) with clamp($v, min: 0, max: 100). It throws a ValueError if min is greater than max.
php -r 'echo clamp(150, 0, 100);'Packages
Add --allowerasing to swap the packages in one step, or use Remi's php84 packages to keep both.
sudo dnf install --allowerasing php8.4 php8.4-fpmPackages
Enable a module stream first: AppStream offers PHP 8.1 to 8.4 as modules.
sudo dnf module enable php:8.4 -yPackages
Ubuntu's own PHP 8.5 needs no PPA. For PHP 8.6, 8.4 or older, use packages.sury.org, which has 26.04 builds.
apt-cache policy php8.4Packages
The curl command already works. If you need the full build, add --allowerasing to swap the packages.
sudo dnf install -y --allowerasing curlProgramming
Seeing "libatomic.so.1: cannot open shared object file"? Install the library; no Node.js reinstall needed.
sudo apt install -y libatomic1Files & directories
Use unxz -k (or xz -dk) to keep the compressed copy, and xzcat to read it without unpacking.
unxz -k file.xzProgramming
Swap random.choice() for secrets.choice() in any code that makes passwords, tokens or keys.
python3 -c "import secrets; print(secrets.token_urlsafe(16))"DevOps & cloud
Run it before every push or in CI: it catches mistakes like an ARG used in FROM with no default value.
docker build --check .System & services
Check which x86-64 levels your CPU supports. If v3 is missing, install the AlmaLinux x86_64_v2 ISO.
/lib64/ld-linux-x86-64.so.2 --help | grep supportedDevOps & cloud
Before updating, check your network backend. If it says "cni", recreate those networks with Netavark first.
podman info --format '{{.Host.NetworkBackend}}'Web servers
Drop "opcache" from extension lists for PHP 8.5, or apt stops with "Unable to locate package".
sudo apt install php8.5-{mysql,curl,xml} -yFiles & directories
Use /var/tmp for temporary files that must survive a restart.
findmnt /tmpFiles & directories
The same goes for /sbin and /lib: everything lives under /usr now.
ls -ld /bin /sbin /libFiles & directories
Admin commands and user commands now live in one directory; old /usr/sbin paths still work.
ls -ld /usr/sbinShell & terminal
Handy when a command fails with "Permission denied".
sudo !!Shell & terminal
Press Ctrl+R again to jump to older matches, Enter to run, Ctrl+G to cancel.
history | grep sshShell & terminal
Perfect for jumping between two directories, like a config folder and a log folder.
cd -Shell & terminal
Or press Alt+. to insert it, so you can see it before running.
cd !$Shell & terminal
Works by default on Ubuntu and Debian, where HISTCONTROL=ignoreboth.
echo $HISTCONTROLShell & terminal
fg brings it back, and jobs lists everything you have paused or sent away.
bgShell & terminal
Add -d to highlight what changed between runs.
watch -d -n 5 df -hDisks & storage
Find such files with lsof +L1, then restart the program or truncate the file instead.
sudo lsof +L1Disks & storage
On a large data disk you can lower it with tune2fs -m and get that space back.
sudo tune2fs -m 1 /dev/sdb1Disks & storage
Check with df -i: every file needs one inode, and millions of tiny files can use them all.
df -iSystem & services
The kernel creates the text when you read the file. Try cat /proc/uptime.
cat /proc/uptimeSystem & services
A quick health check after a reboot or an upgrade.
systemctl --failedSystem & services
The fastest way to find out why a server crashed or rebooted.
journalctl -b -1 -p errSystem & services
List zones with timedatectl list-timezones.
sudo timedatectl set-timezone Asia/KolkataSystem & services
reboot-required.pkgs next to it lists the packages that asked for it.
cat /var/run/reboot-required.pkgsFiles & directories
Without --, rm reads the name as an option and fails.
rm -- -file.txtFiles & directories
Plain cp -r gives the copies new timestamps and makes you the owner.
sudo cp -a /etc/nginx /root/nginx-backupFiles & directories
GNU tar detects the format itself; you only need -z, -J or -j when creating.
tar xf archive.tar.xzSecurity & SSH
With 022 new files are 644 and directories 755; with 002 they are 664 and 775.
umaskNetworking
It replaces netstat, which many distributions no longer install.
sudo ss -tulpnNetworking
A clean replacement for ifconfig, which is no longer installed by default on many systems.
ip -br aNetworking
Great for checking redirects, caching and status codes without downloading the page.
curl -I https://example.comSecurity & SSH
Run it before you step away from an open terminal.
sudo -kSecurity & SSH
No need to close the terminal window. ~? lists the other escape commands.
~.Security & SSH
It creates ~/.ssh with the right permissions and appends your key to authorized_keys.
ssh-copy-id user@serverPackages
To search packages you have not installed yet, use apt-file or dnf provides.
dpkg -S /usr/bin/sshPackages
apt-mark showhold lists held packages; apt-mark unhold releases them.
sudo apt-mark hold nginxKnow a tip worth sharing? Send it to us · Browse the Linux commands cheat sheet