Complete Linux
SysAdmin Cheatsheet
Essential Commands, Scripts & Troubleshooting Guide
Professional Edition v1.0
Created by Zubair H | Localsysadmin
1.0 Last Updated: October 2025
Table of Contents
System Fundamentals Security & Monitoring
▸ File System Management ▸ Permissions & Ownership
▸ User & Group Administration ▸ SELinux & AppArmor
▸ Process Management ▸ System Monitoring
▸ System Information ▸ Log Management
▸ Package Management ▸ Backup & Recovery
Networking Advanced Topics
▸ Network Configuration ▸ Shell Scripting
▸ SSH & Remote Access ▸ Cron Jobs
▸ Firewall Management ▸ Docker & Containers
▸ DNS & Network Diagnostics ▸ Troubleshooting Guide
▸ Web Services ▸ Useful One-Liners
💡 Quick Start Guide
This cheatsheet is organized by topic with practical examples. Use the
table of contents to quickly navigate to the sections most relevant to your
current task.
File System Management
Basic File Operations
COMMAND DESCRIPTION EXAMPLE
ls List directory contents ls -la /home
cp Copy files and directories cp -r source_dir/ dest_dir/
mv Move/rename files mv oldname newname
rm Remove files/directories rm -rf directory/
find Search for files find / -name "*.log"
Disk & Storage Management
Disk Usage Analysis
# Show disk space usage
df -h
# Show directory sizes
du -sh /var/*
# Find large files (>100MB)
find / -type f -size +100M -exec ls -lh {} \;
# Monitor disk I/O
iostat -x 1
File Permissions
Changing Permissions Changing Ownership
# Numeric method # Change owner
chmod 755 [Link] chown user file
# Symbolic method # Change group
chmod u+x,g-w,o-r file chgrp group file
# Recursive # Change both
chmod -R 644 /path/ chown user:group file
# Recursive ownership
chown -R user:group /path/
User & Group Administration
User Management
COMMAND DESCRIPTION EXAMPLE
useradd Create new user useradd -m -s /bin/bash john
usermod Modify user account usermod -aG sudo john
userdel Delete user userdel -r john
passwd Change password passwd john
Group Management
Group Administration Examples
# Create new group
groupadd developers
# Add user to group
usermod -aG developers john
# List user groups
groups john
# Remove user from group
gpasswd -d john developers
# View group members
getent group developers
Sudo Configuration
⚠️ Sudo Security
Be cautious when granting sudo privileges. Use specific commands rather
than ALL when possible.
# Edit sudoers file safely
visudo
# Example sudoers entry
john ALL=(ALL) /usr/bin/systemctl, /usr/bin/apt
# Run command as another user
sudo -u john whoami
Process Management
Process Monitoring
COMMAND DESCRIPTION USAGE
ps Process status ps aux | grep nginx
top Interactive process viewer top -u www-data
htop Enhanced top htop
kill Terminate process kill -9 1234
pkill Kill by name pkill -f nginx
System Monitoring
Resource Monitoring Process Management
# CPU usage # Find process using port
mpstat 1 lsof -i :80
# Memory usage # Show process tree
free -h pstree -p
# I/O statistics # Nice value (priority)
iostat -x 1 nice -n 10 command
renice 15 -p 1234
# Network traffic
iftop # Background jobs
jobs
# Real-time monitoring fg %1
watch -n 1 'df -h; echo; free -h' bg %1
System Services
Systemd Service Management
# Start/stop service
sudo systemctl start nginx
sudo systemctl stop nginx
# Enable/disable service
sudo systemctl enable nginx
sudo systemctl disable nginx
# Check service status
sudo systemctl status nginx
# Reload service config
sudo systemctl reload nginx
# View service logs
sudo journalctl -u nginx -f
Networking
Network Configuration
COMMAND DESCRIPTION EXAMPLE
ip Modern network config ip addr show
ifconfig Legacy network config ifconfig eth0
netstat Network statistics netstat -tulpn
ss Socket statistics ss -tulpn
ping Network connectivity ping [Link]
SSH & Remote Access
SSH Configuration & Usage
# Basic SSH connection
ssh user@hostname
# SSH with specific port
ssh -p 2222 user@hostname
# SSH with key authentication
ssh -i ~/.ssh/[Link] user@hostname
# SSH tunnel
ssh -L 8080:localhost:80 user@hostname
# SCP file transfer
scp [Link] user@hostname:/path/
scp user@hostname:/path/[Link] .
Firewall Management
UFW (Ubuntu) Firewalld (RHEL/CentOS)
# Enable firewall # Start service
sudo ufw enable sudo systemctl start firewalld
# Allow SSH # Allow service
sudo ufw allow ssh sudo firewall-cmd --add-service=http
# Allow specific port # Allow port
sudo ufw allow 8080/tcp sudo firewall-cmd --add-port=8080/tcp
# Deny port # Make permanent
sudo ufw deny 25/tcp sudo firewall-cmd --runtime-to-
permanent
# Status
sudo ufw status verbose # List rules
sudo firewall-cmd --list-all
Security & Monitoring
System Monitoring
Real-time Monitoring Commands
# Monitor system resources
top
htop
# Disk I/O monitoring
iotop
# Network monitoring
nethogs
# Continuous log monitoring
tail -f /var/log/syslog
# Monitor failed login attempts
sudo lastb
# Check for rootkits
sudo rkhunter --check
Log Management
COMMAND DESCRIPTION USAGE
journalctl Systemd journal journalctl -f
tail Follow log files tail -f /var/log/nginx/[Link]
grep Search logs grep "ERROR" /var/log/syslog
logrotate Manage log files logrotate -f /etc/[Link]
Backup & Recovery
File Backups Database Backups
# Simple tar backup # MySQL backup
tar -czf backup-$(date mysqldump -u user -p database >
+%Y%m%d).[Link] /important/data [Link]
# Rsync backup # PostgreSQL backup
rsync -av /source/ pg_dump database > [Link]
/backup/destination/
# MongoDB backup
# Incremental backup with rsync mongodump --host localhost --db mydb
rsync -av --link- --out /backup/
dest=/previous/backup /source/
/new/backup/
🚨 Critical Security Practices
Always test your backups regularly. Store backups in multiple locations
including off-site. Encrypt sensitive backup data.
Advanced Topics
Shell Scripting Essentials
Basic Script Template
#!/bin/bash
# Script: system_info.sh
# Description: Basic system information script
set -e # Exit on error
# Variables
HOSTNAME=$(hostname)
DATE=$(date +%Y-%m-%d)
LOG_FILE="/var/log/system_info.log"
# Functions
check_disk_usage() {
echo "=== Disk Usage ==="
df -h | grep -v tmpfs
}
check_memory() {
echo "=== Memory Usage ==="
free -h
}
# Main script
main() {
echo "System Report for $HOSTNAME - $DATE"
check_disk_usage
check_memory
}
# Execute main function
main "$@"
Cron Jobs
Cron Syntax Cron Management
# Minute Hour Day Month DayOfWeek # Edit user crontab
Command crontab -e
# * * * * *
command # List current crontab
crontab -l
# Examples:
# Every minute # Remove all cron jobs
* * * * * /path/command crontab -r
# Every day at 2:30 AM # System cron (root)
30 2 * * * /path/[Link] sudo crontab -e
# Every Monday at 6 PM # Cron directories
0 18 * * 1 /path/[Link] /etc/[Link]/
/etc/[Link]/
# Every 10 minutes /etc/[Link]/
*/10 * * * * /path/[Link] /etc/[Link]/
Useful One-Liners
Powerful One-Line Commands
# Find and delete old log files
find /var/log -name "*.log" -mtime +30 -delete
# Count lines of code in project
find . -name "*.py" -exec wc -l {} + | tail -1
# Monitor multiple log files simultaneously
tail -f /var/log/nginx/*.log /var/log/mysql/*.log
# Create backup with timestamp
tar -czf "backup-$(date +%Y%m%d-%H%M%S).[Link]" /important/data
# Kill processes matching pattern
pkill -f "python3 [Link]"
# SSH tunnel for MySQL access
ssh -L 3306:localhost:3306 user@dbserver
Troubleshooting Guide
Common Issues & Solutions
Server Not Responding to SSH
1 Check if SSH service is running: sudo systemctl status ssh
2 Verify firewall rules: sudo ufw status
3 Check SSH port: sudo netstat -tulpn | grep :22
4 Examine SSH logs: sudo journalctl -u ssh -f
5 Test from different network
High CPU Usage
1 Identify top processes: top or htop
2 Check for zombie processes: ps aux | grep defunct
3 Monitor system load: uptime
4 Check for runaway scripts: ps aux --sort=-%cpu | head
5 Examine application logs
Disk Space Issues
1 Check disk usage: df -h
2 Find large directories: du -sh /* | sort -hr
3 Check for large log files: find /var/log -type f -size +100M
4 Clear package cache: sudo apt clean or sudo yum clean all
5 Check for core dumps: find / -name "core" -size +10M
Emergency Recovery
🚑 Emergency Procedures
These commands should only be used when the system is unresponsive or
in critical condition.
Emergency Recovery Commands
# Force filesystem check on reboot
sudo touch /forcefsck
# Enter single-user mode (emergency)
sudo systemctl rescue
# Kill process by name (forceful)
pkill -9 process_name
# Remount filesystem as read-write
mount -o remount,rw /
# Emergency memory cleanup
echo 3 > /proc/sys/vm/drop_caches
# Force service restart
sudo systemctl reset-failed service_name
Quick Reference
Most Used Commands
File Operations Networking
▸ ls -la - Detailed listing ▸ ip addr - Network interfaces
▸ cp -r - Recursive copy ▸ netstat -tulpn - Open ports
▸ rm -rf - Force remove ▸ ss -tulpn - Modern netstat
▸ find / -name - Search files ▸ ping - Network test
▸ grep -r "text" - Recursive search ▸ traceroute - Route tracing
System Info Process Management
▸ uname -a - System info ▸ ps aux - All processes
▸ df -h - Disk space ▸ top - Process monitor
▸ free -h - Memory usage ▸ kill -9 - Force kill
▸ uptime - System uptime ▸ pkill - Kill by name
▸ lscpu - CPU information ▸ nice - Process priority
Keyboard Shortcuts
SHORTCUT DESCRIPTION CONTEXT
Ctrl + C Interrupt/Kill process Terminal
Ctrl + Z Suspend process Terminal
Ctrl + D Exit shell Terminal
Ctrl + R Search command history Bash
Ctrl + A Move to line start Terminal
Ctrl + E Move to line end Terminal
ZH
Zubair H
Senior Systems Administrator
With over 8 years of experience in Linux system administration, cloud
infrastructure, and cybersecurity. Passionate about creating
comprehensive guides that help IT professionals work more efficiently.
🎯 Pro Tip
Keep this cheatsheet handy! Bookmark it or print it for quick reference
during critical system administration tasks.