Linux Server Command Cheat Sheet (Everything from This Series on One Page)

Forty tutorials, boiled down. Bookmark it, or print it and stick it next to the server. Where a command needs more explanation, the tutorial number is in brackets.
Terminal shortcuts
| Keys | Does |
|---|---|
| Tab | Complete a file or command name — use constantly |
| ↑ / Ctrl + R | Previous command / search history |
| Ctrl + C | Cancel the running command |
| Ctrl + D | Log out / end input |
| Ctrl + L | Clear the screen |
| Ctrl + A / Ctrl + E | Start / end of line |
| Ctrl + U | Delete the line you're typing |
| sudo !! | Re-run the last command with sudo |
Files and folders (10, 11)
pwd ls -la cd folder cd .. cd
cat f less f head -n 20 f tail -f f
cp a b cp -r d e mv a b rm f rm -r d
mkdir -p a/b/c touch f
find / -name "*.log" 2>/dev/null grep -ri "word" folder/
chmod 644 f chmod 755 d chmod +x s sudo chown -R user:group d
Editing (12)
nano f Ctrl+O Enter = save Ctrl+X = exit Ctrl+W = search Ctrl+K / Ctrl+U = cut / paste
Users (4)
sudo adduser name sudo usermod -aG sudo name sudo deluser --remove-home name
passwd whoami groups su - name
Updates (5, 36)
sudo apt update && sudo apt upgrade -y sudo apt autoremove -y
sudo apt install pkg sudo apt remove pkg apt search word
cat /var/run/reboot-required sudo reboot
Services and logs (13, 14)
systemctl status s sudo systemctl start|stop|restart|reload s
sudo systemctl enable --now s systemctl --failed
journalctl -u s -n 50 journalctl -u s -f journalctl -p err -b
sudo tail -f /var/log/nginx/error.log
Processes and resources (15, 16, 17)
htop free -h uptime nproc df -h sudo ncdu /
ps aux --sort=-%mem | head pgrep -a name kill PID kill -9 PID
sudo ss -tlnp sudo lsof -i :80
Network (2, 8, 9)
hostname -I ip a ip route ping 1.1.1.1 curl ifconfig.me
ssh user@host ssh -p 2222 user@host exit
sudo hostnamectl set-hostname name sudo timedatectl set-timezone Europe/London
sudo netplan try sudo netplan apply
SSH keys and file transfer (3, 18)
ssh-keygen -t ed25519 ssh-copy-id user@host
scp f user@host:~/ scp -r d user@host:~/
rsync -avz --progress d/ user@host:d/
Firewall and Fail2ban (6, 7)
sudo ufw allow OpenSSH sudo ufw allow 80/tcp sudo ufw enable sudo ufw status numbered
sudo ufw delete N sudo ufw allow from 192.168.1.0/24 to any port 445
sudo fail2ban-client status sshd sudo fail2ban-client set sshd unbanip 1.2.3.4
Disks (21, 22)
lsblk -f sudo blkid sudo mkfs.ext4 /dev/sdb1 sudo mount /dev/sdb1 /mnt/data
sudo umount /mnt/data sudo mount -a # test fstab
sudo fallocate -l 2G /swapfile && sudo chmod 600 /swapfile && sudo mkswap /swapfile && sudo swapon /swapfile
Cron and tmux (19, 20)
crontab -e crontab -l sudo crontab -e journalctl -u cron -n 30
0 2 * * * /path/script.sh >> /path/log 2>&1
tmux new -s name Ctrl+B D = detach tmux ls tmux attach -t name
Backup (23)
sudo rsync -a --delete /home/ /mnt/backup/home/
sudo tar -czf /mnt/backup/etc-$(date +%F).tar.gz /etc
sudo mysqldump --all-databases | gzip > db-$(date +%F).sql.gz
tar -xzf file.tar.gz -C /
Docker (24, 25)
docker ps -a docker logs -f name docker stop|start|rm name docker exec -it name bash
docker compose up -d docker compose down docker compose logs -f docker compose ps
docker compose pull && docker compose up -d docker system prune
Nginx and certificates (26, 27, 28)
sudo nginx -t && sudo systemctl reload nginx
/etc/nginx/sites-available/ → ln -s into sites-enabled/
sudo certbot --nginx -d example.com sudo certbot renew --dry-run
MariaDB (29)
sudo mysql
CREATE DATABASE app; CREATE USER 'app'@'localhost' IDENTIFIED BY 'pw'; GRANT ALL ON app.* TO 'app'@'localhost';
When something's wrong, in this order
systemctl --failed
journalctl -p err -b --no-pager | tail -n 30
df -h
free -h
sudo ss -tlnp
docker ps
Wrapping up
If it isn't on this page you probably don't need it yet. Tab to complete, Ctrl + R to find the command you ran last time, and journalctl -u for everything that's ever gone wrong.
