Linux Advanced Cheat Sheet for Sysadmins
Linux Advanced Cheat Sheet for Sysadmins
Linux Advanced Cheat Sheet for Sysadmins
This cheat sheet is for Linux sysadmins who want advanced commands, tuning, and hardening techniques for production-grade systems.
πΉ System Performance & Kernel Tuning
- View Current Sysctl Parameters:
1
sysctl -a # Displays all current kernel parameters
- Set Kernel Parameter Temporarily:
1
sysctl -w net.ipv4.ip_forward=1 # Enables IP forwarding temporarily
- Set Kernel Parameter Persistently:
1 2
echo "net.ipv4.ip_forward = 1" >> /etc/sysctl.conf sysctl -p # Applies changes from /etc/sysctl.conf
Common Sysctl Tunings
- Increase max open files:
1
fs.file-max = 2097152 - Increase TCP backlog:
1
net.core.somaxconn = 1024 - Reuse TIME_WAIT sockets faster:
1 2
net.ipv4.tcp_tw_reuse = 1 net.ipv4.tcp_fin_timeout = 15
- Increase network buffers:
1 2
net.core.rmem_max = 16777216 net.core.wmem_max = 16777216
πΉ Advanced Storage & Filesystems
- Check Filesystem Usage:
1
df -hT # Displays disk usage with filesystem types
- Check Inode Usage:
1
df -i # Displays inode usage
- Create LVM Partition:
1 2 3 4
pvcreate /dev/sdb # Initializes a physical volume vgcreate vg_data /dev/sdb # Creates a volume group lvcreate -L 10G -n lv_data vg_data # Creates a logical volume mkfs.ext4 /dev/vg_data/lv_data # Formats the logical volume with ext4
- Resize LVM:
1 2
lvextend -L +5G /dev/vg_data/lv_data # Extends the logical volume by 5GB resize2fs /dev/vg_data/lv_data # Resizes the filesystem to use the new space
- Check RAID Status:
1
cat /proc/mdstat # Displays RAID status
- Check Filesystem Errors:
1
fsck -f /dev/sda1 # Checks and fixes filesystem errors
πΉ Networking Advanced
- Check Routing Table:
1
ip route show # Displays the routing table - Add Static Route:
1
ip route add 10.0.0.0/24 via 192.168.1.1 # Adds a static route - Check Connections (like netstat):
1
ss -tulnp # Displays listening ports and connections
- Traceroute:
1
traceroute google.com # Traces the route to a host - Check Packet Loss:
1
mtr example.com # Combines ping and traceroute for packet loss analysis - Capture Packets:
1
tcpdump -i eth0 port 80 # Captures packets on port 80
πΉ Systemd Deep Dive
- List All Services:
1
systemctl list-units --type=service # Lists all active services
- Mask a Service (prevent from starting ever):
1
sudo systemctl mask service # Prevents a service from starting
- Unmask a Service:
1
sudo systemctl unmask service # Removes the mask from a service
- Check Boot Performance:
1 2
systemd-analyze # Analyzes boot performance systemd-analyze blame # Shows time taken by each service during boot
- View Logs Since Last Boot:
1
journalctl -b # Displays logs since the last boot
πΉ Security & Hardening
SELinux / AppArmor
- Check SELinux Mode:
1
getenforce # Displays the current SELinux mode - Change SELinux Mode:
1 2
setenforce 1 # Enforcing mode setenforce 0 # Permissive mode
- AppArmor Status:
1
aa-status # Displays AppArmor status
Firewall (UFW / firewalld)
- Allow Port (UFW):
1
sudo ufw allow 22/tcp # Allows SSH traffic
- Firewalld Add Port:
1 2
sudo firewall-cmd --add-port=443/tcp --permanent # Opens port 443 sudo firewall-cmd --reload # Reloads firewall rules
Audit & Intrusion Detection
- Auditd Logs:
1
ausearch -m avc # Searches audit logs for access vector cache messages
- Fail2Ban Setup:
1
sudo fail2ban-client status # Displays Fail2Ban status
SSH Hardening
- Disable root login:
1 2
# Edit /etc/ssh/sshd_config PermitRootLogin no - Disable password authentication:
1 2
# Edit /etc/ssh/sshd_config PasswordAuthentication no
πΉ Debugging & Troubleshooting
- Check Last System Reboots:
1
last reboot # Displays reboot history - Check Crashes (kernel logs):
1
journalctl -k -p err # Displays kernel error logs
- Check CPU Usage per Core:
1
mpstat -P ALL 1 # Displays CPU usage per core every second
- Check IO Wait & Disk Load:
1
iostat -xz 1 # Displays disk I/O statistics
- Check Open Network Connections:
1
lsof -i -P -n # Lists open network connections
- Strace Process (syscalls):
1
strace -p <pid> # Traces system calls made by a process
πΉ Useful Tools
- htop β Interactive process viewer
- iftop β Network traffic monitor
- iotop β Disk I/O usage by process
- ncdu β Disk usage analyzer (better than
du) - atop β Advanced system resource monitor
- glances β Cross-platform system monitoring tool
πΉ Legend (Advanced Sysadmin Terms)
- Sysctl β Interface to modify kernel parameters.
- OOM Killer β Kernel process that kills apps when out of memory.
- LVM β Logical Volume Manager, flexible disk management.
- RAID β Redundant Array of Inexpensive Disks.
- SELinux/AppArmor β Mandatory access control security systems.
- auditd β Linux auditing system for security logs.
- systemd-analyze β Tool for boot performance profiling.
- tcpdump β Low-level packet capture tool.
- strace β Debugging tool to trace system calls.
πΉ Best Practices
- Keep
/var,/home, and/tmpon separate partitions. - Use
sysctlfor kernel/network tuning (but document changes!). - Monitor system performance with
sar,iostat,vmstat. - Always enforce SSH key authentication, disable password login.
- Apply least privilege β donβt give users full sudo unless required.
- Automate regular security scans with
lynis,clamav, oropenvas. - Backup configs in
/etcand regularly test restores. - Use monitoring systems (Prometheus, Zabbix, Nagios).
This post is licensed under CC BY 4.0 by the author.