🐧 Linux Commands Cheat Sheet

Essential commands every sysadmin needs • PragmaticSysadmin.help

File System Navigation

CommandDescription
pwdPrint working directory
ls -laList all files with details
cd /pathChange directory
cd ~Go to home directory
cd -Go to previous directory
tree -L 2Show directory tree (2 levels)

File Operations

CommandDescription
cp -r src/ dest/Copy directory recursively
mv old newMove/rename file
rm -rf dir/Remove directory forcefully
mkdir -p a/b/cCreate nested directories
touch fileCreate empty file / update timestamp
ln -s target linkCreate symbolic link

File Viewing & Search

CommandDescription
cat fileDisplay file contents
less fileView file with pagination
head -n 20 fileFirst 20 lines
tail -f fileFollow file updates (live)
grep -r "pattern" .Search recursively
grep -i "pattern" fileCase-insensitive search
find . -name "*.log"Find files by name
find . -size +100MFind files larger than 100MB

Process Management

CommandDescription
ps auxList all processes
ps aux | grep javaFind specific process
topInteractive process viewer
htopEnhanced process viewer
kill -9 PIDForce kill process
killall nginxKill all nginx processes
pgrep -f "node"Find PIDs by pattern
pkill -f "script"Kill by pattern match

System Information

CommandDescription
uname -aKernel info
cat /etc/os-releaseOS version
uptimeSystem uptime & load
hostnameSystem hostname
free -hMemory usage
df -hDisk space
CommandDescription
du -sh *Directory sizes
lscpuCPU information
nprocNumber of CPUs
dmesgKernel messages
journalctl -xeSystem logs
lastLogin history

User & Permissions

CommandDescription
chmod 755 filerwx for owner, rx for others
chmod -R 644 dir/Recursive permission change
chown user:group fileChange ownership
whoamiCurrent username
idUser/group IDs
sudo -u user cmdRun as different user

Package Management

Debian/Ubuntu (apt)
apt updateUpdate package list
apt upgradeUpgrade packages
apt install pkgInstall package
apt remove pkgRemove package
RHEL/CentOS (dnf/yum)
dnf updateUpdate packages
dnf install pkgInstall package
dnf remove pkgRemove package
dnf search pkgSearch packages

Service Management (systemd)

CommandDescription
systemctl status nginxCheck service status
systemctl start nginxStart service
systemctl stop nginxStop service
systemctl restart nginxRestart service
systemctl enable nginxEnable at boot
systemctl disable nginxDisable at boot
systemctl list-units --type=serviceList all services
journalctl -u nginx -fFollow service logs

Compression & Archives

CommandDescription
tar -czvf archive.tar.gz dir/Create gzip archive
tar -xzvf archive.tar.gzExtract gzip archive
zip -r archive.zip dir/Create zip archive
unzip archive.zipExtract zip archive
gzip fileCompress file
gunzip file.gzDecompress file

🌐 Networking Cheat Sheet

Troubleshooting commands and diagnostics • PragmaticSysadmin.help

Connectivity Testing

CommandDescription
ping -c 4 google.comPing 4 times (Linux)
ping -n 4 google.comPing 4 times (Windows)
ping -s 1000 hostPing with packet size
traceroute google.comTrace route (Linux/macOS)
tracert google.comTrace route (Windows)
mtr google.comMy traceroute (continuous)
tracepath google.comTrace path (simpler)

DNS Troubleshooting

CommandDescription
nslookup google.comDNS lookup
dig google.comDetailed DNS query
dig google.com +shortJust the IP
dig @8.8.8.8 google.comQuery specific DNS
dig -x 192.168.1.1Reverse DNS lookup
host google.comSimple DNS lookup

Network Interfaces & IPs

CommandDescription
ip addr showShow all interfaces
ip addr show eth0Show specific interface
ip link set eth0 upBring interface up
ip link set eth0 downBring interface down
ip routeShow routing table
ip route add default via 192.168.1.1Add default gateway
ifconfigLegacy interface info
ifconfig eth0Specific interface info

Port & Connection Analysis

CommandDescription
netstat -tulpnListening ports & services
netstat -an | grep ESTABLISHEDActive connections
ss -tulpnSocket statistics (modern)
ss -sSocket summary
lsof -i :80What's using port 80
lsof -i -PAll open network files
nc -zv host 22Test if port is open
nmap -sV hostService version detection

Bandwidth & Traffic

CommandDescription
iftopReal-time bandwidth usage
nethogsPer-process bandwidth
vnstat -dDaily network statistics
ethtool eth0Interface statistics
tcpdump -i eth0Capture packets
tcpdump -i eth0 port 80Capture specific port
wiresharkGUI packet analysis

Firewall (iptables/ufw)

iptables
iptables -L -nList rules
iptables -A INPUT -p tcp --dport 22 -j ACCEPTAllow SSH
iptables -A INPUT -j DROPDrop all other
iptables-saveSave rules
ufw (Ubuntu)
ufw statusShow status
ufw allow 22Allow port 22
ufw enableEnable firewall
ufw deny 80Block port 80

SSH & Remote Access

CommandDescription
ssh user@hostConnect to remote host
ssh -p 2222 user@hostConnect on custom port
ssh -i key.pem user@hostConnect with key file
ssh -L 8080:localhost:80 hostLocal port forwarding
ssh -R 8080:localhost:80 hostRemote port forwarding
scp file user@host:/pathCopy file to remote
scp user@host:/path/file .Copy file from remote
rsync -avz src/ user@host:dest/Sync directories

🔒 Security Hardening Cheat Sheet

Quick security checklist for servers • PragmaticSysadmin.help

User & Access Security

Command / ActionDescription
passwd -l usernameLock user account
userdel -r usernameRemove user & home dir
awk -F: '$3 == 0 {print $1}' /etc/passwdFind root users
lastb | headFailed login attempts
faillock --user username --resetClear faillock for user

SSH Hardening

SettingRecommendation
PermitRootLoginSet to no in /etc/ssh/sshd_config
PasswordAuthenticationSet to no (use keys only)
PortChange from default 22
MaxAuthTriesSet to 3
ProtocolEnsure only Protocol 2
AllowUsersRestrict to specific users

File Permissions Audit

CommandDescription
find / -perm -4000 2>/dev/nullFind SUID files
find / -perm -2000 2>/dev/nullFind SGID files
find / -type f -perm 0777 2>/dev/nullFind world-writable files
find /home -perm -0002 2>/dev/nullFind writable files in home
ls -la /etc/passwd /etc/shadowCheck auth file perms

Service Hardening

CommandDescription
systemctl list-unit-files --state=enabledList enabled services
systemctl disable servicenameDisable unnecessary service
ss -tulpnCheck listening ports
netstat -tulpn | grep LISTENAlternative port check

Update & Patch Management

Debian/Ubuntu
apt updateRefresh package list
apt upgrade -yInstall updates
apt autoremoveRemove unused packages
unattended-upgradeAuto security updates
RHEL/CentOS
dnf check-updateCheck for updates
dnf upgrade -yInstall updates
dnf autoremoveRemove unused packages
dnf updateinfo listSecurity updates list

Log Monitoring

CommandDescription
journalctl -xeRecent system logs
journalctl -u sshd -fFollow SSH logs
tail -f /var/log/auth.logAuthentication logs (Debian)
tail -f /var/log/secureAuthentication logs (RHEL)
grep "Failed password" /var/log/auth.logFailed login attempts

Network Security Checklist

ItemCheck
Open portsOnly necessary ports open
FirewallConfigured and enabled
Unused servicesDisabled or removed
SSH keysPassword auth disabled
Fail2BanInstalled and configured
SSL/TLSCertificates up to date

Quick Security Audit Commands

CommandDescription
cat /etc/passwd | grep -v nologinList users with shells
last | head -20Recent logins
wWho is logged in now
crontab -lUser cron jobs
cat /etc/crontabSystem cron jobs
uptimeSystem uptime & load

Essential Security Tools

ToolPurpose
lynisSecurity auditing
rkhunterRootkit scanner
chkrootkitRootkit detection
clamavAntivirus scanner
ToolPurpose
fail2banIntrusion prevention
aideFile integrity
logwatchLog analysis
auditdAudit daemon