Essential commands every sysadmin needs • PragmaticSysadmin.help
| Command | Description |
|---|---|
pwd | Print working directory |
ls -la | List all files with details |
cd /path | Change directory |
cd ~ | Go to home directory |
cd - | Go to previous directory |
tree -L 2 | Show directory tree (2 levels) |
| Command | Description |
|---|---|
cp -r src/ dest/ | Copy directory recursively |
mv old new | Move/rename file |
rm -rf dir/ | Remove directory forcefully |
mkdir -p a/b/c | Create nested directories |
touch file | Create empty file / update timestamp |
ln -s target link | Create symbolic link |
| Command | Description |
|---|---|
cat file | Display file contents |
less file | View file with pagination |
head -n 20 file | First 20 lines |
tail -f file | Follow file updates (live) |
grep -r "pattern" . | Search recursively |
grep -i "pattern" file | Case-insensitive search |
find . -name "*.log" | Find files by name |
find . -size +100M | Find files larger than 100MB |
| Command | Description |
|---|---|
ps aux | List all processes |
ps aux | grep java | Find specific process |
top | Interactive process viewer |
htop | Enhanced process viewer |
kill -9 PID | Force kill process |
killall nginx | Kill all nginx processes |
pgrep -f "node" | Find PIDs by pattern |
pkill -f "script" | Kill by pattern match |
| Command | Description |
|---|---|
uname -a | Kernel info |
cat /etc/os-release | OS version |
uptime | System uptime & load |
hostname | System hostname |
free -h | Memory usage |
df -h | Disk space |
| Command | Description |
|---|---|
du -sh * | Directory sizes |
lscpu | CPU information |
nproc | Number of CPUs |
dmesg | Kernel messages |
journalctl -xe | System logs |
last | Login history |
| Command | Description |
|---|---|
chmod 755 file | rwx for owner, rx for others |
chmod -R 644 dir/ | Recursive permission change |
chown user:group file | Change ownership |
whoami | Current username |
id | User/group IDs |
sudo -u user cmd | Run as different user |
| Debian/Ubuntu (apt) | |
|---|---|
apt update | Update package list |
apt upgrade | Upgrade packages |
apt install pkg | Install package |
apt remove pkg | Remove package |
| RHEL/CentOS (dnf/yum) | |
|---|---|
dnf update | Update packages |
dnf install pkg | Install package |
dnf remove pkg | Remove package |
dnf search pkg | Search packages |
| Command | Description |
|---|---|
systemctl status nginx | Check service status |
systemctl start nginx | Start service |
systemctl stop nginx | Stop service |
systemctl restart nginx | Restart service |
systemctl enable nginx | Enable at boot |
systemctl disable nginx | Disable at boot |
systemctl list-units --type=service | List all services |
journalctl -u nginx -f | Follow service logs |
| Command | Description |
|---|---|
tar -czvf archive.tar.gz dir/ | Create gzip archive |
tar -xzvf archive.tar.gz | Extract gzip archive |
zip -r archive.zip dir/ | Create zip archive |
unzip archive.zip | Extract zip archive |
gzip file | Compress file |
gunzip file.gz | Decompress file |
Troubleshooting commands and diagnostics • PragmaticSysadmin.help
| Command | Description |
|---|---|
ping -c 4 google.com | Ping 4 times (Linux) |
ping -n 4 google.com | Ping 4 times (Windows) |
ping -s 1000 host | Ping with packet size |
traceroute google.com | Trace route (Linux/macOS) |
tracert google.com | Trace route (Windows) |
mtr google.com | My traceroute (continuous) |
tracepath google.com | Trace path (simpler) |
| Command | Description |
|---|---|
nslookup google.com | DNS lookup |
dig google.com | Detailed DNS query |
dig google.com +short | Just the IP |
dig @8.8.8.8 google.com | Query specific DNS |
dig -x 192.168.1.1 | Reverse DNS lookup |
host google.com | Simple DNS lookup |
| Command | Description |
|---|---|
ip addr show | Show all interfaces |
ip addr show eth0 | Show specific interface |
ip link set eth0 up | Bring interface up |
ip link set eth0 down | Bring interface down |
ip route | Show routing table |
ip route add default via 192.168.1.1 | Add default gateway |
ifconfig | Legacy interface info |
ifconfig eth0 | Specific interface info |
| Command | Description |
|---|---|
netstat -tulpn | Listening ports & services |
netstat -an | grep ESTABLISHED | Active connections |
ss -tulpn | Socket statistics (modern) |
ss -s | Socket summary |
lsof -i :80 | What's using port 80 |
lsof -i -P | All open network files |
nc -zv host 22 | Test if port is open |
nmap -sV host | Service version detection |
| Command | Description |
|---|---|
iftop | Real-time bandwidth usage |
nethogs | Per-process bandwidth |
vnstat -d | Daily network statistics |
ethtool eth0 | Interface statistics |
tcpdump -i eth0 | Capture packets |
tcpdump -i eth0 port 80 | Capture specific port |
wireshark | GUI packet analysis |
| iptables | |
|---|---|
iptables -L -n | List rules |
iptables -A INPUT -p tcp --dport 22 -j ACCEPT | Allow SSH |
iptables -A INPUT -j DROP | Drop all other |
iptables-save | Save rules |
| ufw (Ubuntu) | |
|---|---|
ufw status | Show status |
ufw allow 22 | Allow port 22 |
ufw enable | Enable firewall |
ufw deny 80 | Block port 80 |
| Command | Description |
|---|---|
ssh user@host | Connect to remote host |
ssh -p 2222 user@host | Connect on custom port |
ssh -i key.pem user@host | Connect with key file |
ssh -L 8080:localhost:80 host | Local port forwarding |
ssh -R 8080:localhost:80 host | Remote port forwarding |
scp file user@host:/path | Copy file to remote |
scp user@host:/path/file . | Copy file from remote |
rsync -avz src/ user@host:dest/ | Sync directories |
Quick security checklist for servers • PragmaticSysadmin.help
| Command / Action | Description |
|---|---|
passwd -l username | Lock user account |
userdel -r username | Remove user & home dir |
awk -F: '$3 == 0 {print $1}' /etc/passwd | Find root users |
lastb | head | Failed login attempts |
faillock --user username --reset | Clear faillock for user |
| Setting | Recommendation |
|---|---|
PermitRootLogin | Set to no in /etc/ssh/sshd_config |
PasswordAuthentication | Set to no (use keys only) |
Port | Change from default 22 |
MaxAuthTries | Set to 3 |
Protocol | Ensure only Protocol 2 |
AllowUsers | Restrict to specific users |
| Command | Description |
|---|---|
find / -perm -4000 2>/dev/null | Find SUID files |
find / -perm -2000 2>/dev/null | Find SGID files |
find / -type f -perm 0777 2>/dev/null | Find world-writable files |
find /home -perm -0002 2>/dev/null | Find writable files in home |
ls -la /etc/passwd /etc/shadow | Check auth file perms |
| Command | Description |
|---|---|
systemctl list-unit-files --state=enabled | List enabled services |
systemctl disable servicename | Disable unnecessary service |
ss -tulpn | Check listening ports |
netstat -tulpn | grep LISTEN | Alternative port check |
| Debian/Ubuntu | |
|---|---|
apt update | Refresh package list |
apt upgrade -y | Install updates |
apt autoremove | Remove unused packages |
unattended-upgrade | Auto security updates |
| RHEL/CentOS | |
|---|---|
dnf check-update | Check for updates |
dnf upgrade -y | Install updates |
dnf autoremove | Remove unused packages |
dnf updateinfo list | Security updates list |
| Command | Description |
|---|---|
journalctl -xe | Recent system logs |
journalctl -u sshd -f | Follow SSH logs |
tail -f /var/log/auth.log | Authentication logs (Debian) |
tail -f /var/log/secure | Authentication logs (RHEL) |
grep "Failed password" /var/log/auth.log | Failed login attempts |
| Item | Check |
|---|---|
| Open ports | Only necessary ports open |
| Firewall | Configured and enabled |
| Unused services | Disabled or removed |
| SSH keys | Password auth disabled |
| Fail2Ban | Installed and configured |
| SSL/TLS | Certificates up to date |
| Command | Description |
|---|---|
cat /etc/passwd | grep -v nologin | List users with shells |
last | head -20 | Recent logins |
w | Who is logged in now |
crontab -l | User cron jobs |
cat /etc/crontab | System cron jobs |
uptime | System uptime & load |
| Tool | Purpose |
|---|---|
lynis | Security auditing |
rkhunter | Rootkit scanner |
chkrootkit | Rootkit detection |
clamav | Antivirus scanner |
| Tool | Purpose |
|---|---|
fail2ban | Intrusion prevention |
aide | File integrity |
logwatch | Log analysis |
auditd | Audit daemon |