A quick reference for Linux system administration. Bookmark this page.
System Information
# OS and kernel
cat /etc/os-release
uname -r # Kernel version
hostnamectl # Hostname, OS, kernel, arch
# Hardware
lscpu # CPU info
free -h # Memory usage
lsblk # Block devices
lspci # PCI devices
lsusb # USB devices
dmidecode -t memory # RAM details (needs root)User and Group Management
# Users
useradd -m -s /bin/bash newuser # Create user with home dir
usermod -aG sudo newuser # Add to sudo group
userdel -r olduser # Delete user and home
passwd username # Change password
id username # Show user info
whoami # Current user
# Groups
groupadd devteam
usermod -aG devteam username
groups usernamePackage Management
# RHEL/CentOS/Rocky (dnf/yum)
sudo dnf update # Update all packages
sudo dnf install nginx # Install package
sudo dnf remove nginx # Remove package
sudo dnf search "web server" # Search
sudo dnf info nginx # Package info
sudo dnf list installed # List installed
# Ubuntu/Debian (apt)
sudo apt update && sudo apt upgrade
sudo apt install nginx
sudo apt remove nginx
sudo apt autoremove # Remove unused deps
apt search "web server"
apt show nginxService Management (systemd)
# Start/stop/restart
sudo systemctl start nginx
sudo systemctl stop nginx
sudo systemctl restart nginx
sudo systemctl reload nginx # Reload config without restart
# Enable/disable on boot
sudo systemctl enable nginx
sudo systemctl disable nginx
sudo systemctl enable --now nginx # Enable and start
# Status and logs
systemctl status nginx
journalctl -u nginx # Service logs
journalctl -u nginx -f # Follow logs
journalctl -u nginx --since today # Today's logs
journalctl -u nginx --since "1 hour ago"File System
# Disk usage
df -h # Filesystem usage
du -sh /var/log # Directory size
du -sh * | sort -rh | head -10 # Largest items
# Find files
find / -name "*.conf" -type f
find /var/log -mtime -1 # Modified in last day
find / -size +100M # Files over 100MB
locate filename # Fast search (needs updatedb)
# Mount
mount /dev/sdb1 /mnt/data
umount /mnt/data
cat /etc/fstab # Persistent mountsNetworking
# IP and interfaces
ip addr show
ip route show
ip link show
# DNS
dig example.com
nslookup example.com
cat /etc/resolv.conf
# Connections and ports
ss -tlnp # Listening TCP ports
ss -tunap # All connections
netstat -tlnp # (legacy, same as ss)
# Firewall (firewalld)
sudo firewall-cmd --list-all
sudo firewall-cmd --add-port=8080/tcp --permanent
sudo firewall-cmd --reload
# Firewall (ufw - Ubuntu)
sudo ufw status
sudo ufw allow 80/tcp
sudo ufw enableSSH
# Connect
ssh user@host
ssh -i ~/.ssh/key.pem user@host
ssh -p 2222 user@host # Custom port
# Key management
ssh-keygen -t ed25519 -C "email@example.com"
ssh-copy-id user@host # Copy public key to server
# SSH tunnel
ssh -L 8080:localhost:80 user@host # Local port forward
ssh -R 8080:localhost:80 user@host # Remote port forward
ssh -D 1080 user@host # SOCKS proxyTips and Tricks
- Use
alias ll='ls -lah'in.bashrcfor quick listing - Use
ctrl+rfor reverse history search - Use
screenortmuxfor persistent sessions - Use
watch -n 5 commandto repeat command every 5 seconds - Use
teeto write to file and stdout:command | tee output.log