Linux System Administration Fundamentals: Complete Server Management Guide
Master essential Linux system administration skills including user management, security hardening, and system monitoring. Learn practical techniques for managing production Linux servers efficiently.
📑 Table of Contents
- Introduction to Linux System Administration
- 1. User and Group Management
- Creating and Managing Users
- Group Management
- Sudo and Privilege Escalation
- 2. System Monitoring and Performance
- Real-time Monitoring Tools
- Performance Analysis
- Resource Limits
- 3. Security Hardening
- SSH Security Configuration
- Firewall Configuration
- System Hardening Checklist
- 4. Log Management and Analysis
- Systemd Journal Management
- Traditional Log Files
- Log Rotation
- 5. Package Management
- Debian/Ubuntu (APT)
- RHEL/CentOS (DNF/YUM)
- 6. Service Management with Systemd
- Service Control
- Creating Custom Services
- 7. Backup and Recovery
- File System Backups
- Database Backups
- 8. Disk and Storage Management
- Disk Operations
- LVM Management
- 9. Network Configuration
- Network Management
- 10. Automation and Cron Jobs
- Cron Scheduling
- Frequently Asked Questions
- What are the most important skills for a Linux system administrator?
- How do I secure a Linux server?
- What’s the difference between systemctl and service commands?
- How often should I backup Linux servers?
- What monitoring tools should I use?
- How do I troubleshoot high CPU usage?
- What’s the best way to learn Linux system administration?
- How do I manage multiple servers efficiently?
- What logs should I monitor regularly?
- How do I recover from a failed system update?
- Conclusion
Introduction to Linux System Administration
System administration forms the backbone of any Linux infrastructure. Whether managing a single server or an entire data center, mastering fundamental sysadmin skills is crucial for maintaining reliable, secure, and high-performing systems. This comprehensive guide covers essential techniques every Linux administrator needs.
1. User and Group Management
Creating and Managing Users
# Create user with specific home directory and shell
sudo useradd -m -d /home/webapp -s /bin/bash -c "Web Application User" webapp
# Set password and force change on first login
sudo passwd webapp
sudo chage -d 0 webapp
# Add user to multiple groups
sudo usermod -a -G sudo,docker,www-data webapp
# Set user account expiration
sudo chage -E 2024-12-31 webapp
# Lock/unlock user account
sudo usermod -L webapp # Lock
sudo usermod -U webapp # Unlock
# Delete user and home directory
sudo userdel -r webapp
Group Management
# Create group
sudo groupadd developers
# Add user to group
sudo usermod -a -G developers username
# Remove user from group
sudo gpasswd -d username developers
# View user's groups
groups username
id username
Sudo and Privilege Escalation
# Configure sudo access
sudo visudo
# Allow user to run specific commands
username ALL=(ALL) /usr/bin/systemctl restart nginx
# Allow passwordless sudo for group
%admin ALL=(ALL) NOPASSWD: ALL
# Restrict sudo to specific commands
%developers ALL=(ALL) /usr/bin/git, /usr/bin/docker
2. System Monitoring and Performance
Real-time Monitoring Tools
# Monitor system resources
htop # Interactive process viewer
iotop -o # I/O usage by process
neth ogs # Network usage by process
glances # All-in-one monitoring
# Check system information
lscpu # CPU details
free -h # Memory usage
df -h # Disk usage
lsblk # Block devices
uptime # System uptime and load
Performance Analysis
# Monitor processes
ps aux --sort=-%cpu | head -10 # Top CPU consumers
ps aux --sort=-%mem | head -10 # Top memory consumers
# System load analysis
vmstat 1 10 # Virtual memory statistics
iostat -x 1 10 # I/O statistics
sar -u 1 10 # CPU usage over time
# Network performance
nethogs # Network bandwidth by process
iftop # Network traffic by connection
ss -tunap # Socket statistics
Resource Limits
# Set user limits (/etc/security/limits.conf)
webapp soft nofile 4096
webapp hard nofile 8192
webapp soft nproc 1024
webapp hard nproc 2048
# View current limits
ulimit -a
# Set systemd service limits
[Service]
LimitNOFILE=8192
LimitNPROC=2048
3. Security Hardening
SSH Security Configuration
# Configure SSH security (/etc/ssh/sshd_config)
sudo nano /etc/ssh/sshd_config
# Recommended settings:
PermitRootLogin no
PasswordAuthentication no
PubkeyAuthentication yes
Port 2222
AllowUsers admin deploy
MaxAuthTries 3
ClientAliveInterval 300
ClientAliveCountMax 2
# Restart SSH
sudo systemctl restart sshd
Firewall Configuration
# UFW (Ubuntu/Debian)
sudo ufw enable
sudo ufw default deny incoming
sudo ufw default allow outgoing
sudo ufw allow ssh
sudo ufw allow 80/tcp
sudo ufw allow 443/tcp
sudo ufw status verbose
# Firewalld (RHEL/CentOS)
sudo firewall-cmd --permanent --add-service=ssh
sudo firewall-cmd --permanent --add-service=http
sudo firewall-cmd --permanent --add-service=https
sudo firewall-cmd --reload
System Hardening Checklist
- Disable unnecessary services
- Keep system updated with security patches
- Configure SELinux/AppArmor
- Enable automatic security updates
- Implement fail2ban for brute force protection
- Use strong password policies
- Regular security audits with lynis
4. Log Management and Analysis
Systemd Journal Management
# View system logs
journalctl -f # Follow logs in real-time
journalctl -u ssh.service # Service-specific logs
journalctl --since yesterday # Time-based filtering
journalctl --priority=err # Priority filtering
journalctl -b # Current boot logs
journalctl -k # Kernel messages
# Export logs
journalctl -u nginx > nginx.log
journalctl --since "2024-01-01" -o json > system.json
Traditional Log Files
# Important log locations
/var/log/syslog # System messages
/var/log/auth.log # Authentication logs
/var/log/kern.log # Kernel logs
/var/log/apache2/ # Web server logs
/var/log/mysql/ # Database logs
# Monitor logs in real-time
tail -f /var/log/syslog
multitail /var/log/syslog /var/log/auth.log
Log Rotation
# Configure log rotation (/etc/logrotate.d/webapp)
/var/log/webapp/*.log {
daily
rotate 30
compress
delaycompress
missingok
notifempty
create 644 webapp webapp
sharedscripts
postrotate
systemctl reload webapp
endscript
}
5. Package Management
Debian/Ubuntu (APT)
# Update and upgrade
sudo apt update
sudo apt upgrade -y
sudo apt dist-upgrade
# Install packages
sudo apt install nginx postgresql
# Remove packages
sudo apt remove --purge nginx
sudo apt autoremove
# Search packages
apt search keyword
apt show package-name
RHEL/CentOS (DNF/YUM)
# Update system
sudo dnf update -y
# Install packages
sudo dnf install httpd mariadb-server
# Remove packages
sudo dnf remove httpd
# Search packages
dnf search keyword
dnf info package-name
6. Service Management with Systemd
Service Control
# Start/stop/restart services
sudo systemctl start nginx
sudo systemctl stop nginx
sudo systemctl restart nginx
sudo systemctl reload nginx
# Enable/disable on boot
sudo systemctl enable nginx
sudo systemctl disable nginx
# Check status
systemctl status nginx
systemctl is-active nginx
systemctl is-enabled nginx
Creating Custom Services
# Create service file (/etc/systemd/system/myapp.service)
[Unit]
Description=My Application
After=network.target
[Service]
Type=simple
User=webapp
WorkingDirectory=/opt/myapp
ExecStart=/usr/bin/node server.js
Restart=always
RestartSec=10
[Install]
WantedBy=multi-user.target
# Enable and start
sudo systemctl daemon-reload
sudo systemctl enable --now myapp
7. Backup and Recovery
File System Backups
# Rsync backups
rsync -avz /data/ /backup/data/
rsync -avz -e ssh /data/ user@remote:/backup/
# Tar archives
tar -czf backup-$(date +%Y%m%d).tar.gz /etc /home
tar -xzf backup-20241003.tar.gz
# Incremental backups with rsnapshot
sudo rsnapshot daily
sudo rsnapshot weekly
Database Backups
# MySQL/MariaDB
mysqldump -u root -p database_name > backup.sql
mysqldump -u root -p --all-databases > all_databases.sql
# PostgreSQL
pg_dump dbname > backup.sql
pg_dumpall > all_databases.sql
# Automated backup script
#!/bin/bash
DATE=$(date +%Y%m%d)
mysqldump -u root -p$PASS db > /backup/db_$DATE.sql
find /backup -name "db_*.sql" -mtime +30 -delete
8. Disk and Storage Management
Disk Operations
# Check disk usage
df -h
du -sh /var/*
ncdu /var/log
# Partition management
fdisk -l
parted /dev/sdb
lsblk -f
# Mount filesystems
mount /dev/sdb1 /mnt/data
umount /mnt/data
# Persistent mounts (/etc/fstab)
/dev/sdb1 /mnt/data ext4 defaults 0 2
LVM Management
# Create LVM
pvcreate /dev/sdb
vgcreate vg_data /dev/sdb
lvcreate -L 50G -n lv_data vg_data
mkfs.ext4 /dev/vg_data/lv_data
# Extend volume
lvextend -L +20G /dev/vg_data/lv_data
resize2fs /dev/vg_data/lv_data
9. Network Configuration
Network Management
# View network configuration
ip addr show
ip route show
nmcli device status
# Configure static IP (netplan - Ubuntu)
network:
version: 2
ethernets:
eth0:
addresses: [192.168.1.100/24]
gateway4: 192.168.1.1
nameservers:
addresses: [8.8.8.8, 8.8.4.4]
# Apply configuration
sudo netplan apply
# Test connectivity
ping -c 4 google.com
traceroute google.com
mtr google.com
10. Automation and Cron Jobs
Cron Scheduling
# Edit crontab
crontab -e
# Backup database daily at 2 AM
0 2 * * * /scripts/backup-db.sh
# Clean logs weekly
0 3 * * 0 find /var/log -type f -mtime +30 -delete
# System update monthly
0 4 1 * * apt update && apt upgrade -y
Frequently Asked Questions
What are the most important skills for a Linux system administrator?
Core skills include: user/permission management, service configuration, security hardening, troubleshooting, scripting automation, networking basics, and backup/recovery procedures. Strong command-line proficiency is essential.
How do I secure a Linux server?
Key steps: disable root SSH login, use key-based authentication, configure firewall, keep system updated, enable SELinux/AppArmor, implement fail2ban, use strong passwords, regular security audits, and minimize installed packages.
What’s the difference between systemctl and service commands?
systemctl is the modern systemd command for managing services. The service command is a legacy wrapper that works with both systemd and older init systems. Use systemctl for new systems.
How often should I backup Linux servers?
Daily incremental backups for data, weekly full backups for systems, and before any major changes. Critical databases should be backed up more frequently, potentially hourly with transaction logs.
What monitoring tools should I use?
Essential tools: htop (processes), iotop (I/O), nethogs (network), journalctl (logs). For comprehensive monitoring: Prometheus+Grafana, Nagios, or Zabbix for infrastructure-wide visibility.
How do I troubleshoot high CPU usage?
Use top/htop to identify process, check with ps aux, examine logs with journalctl, use strace for system calls, profile with perf. Consider load average, I/O wait, and context switches.
What’s the best way to learn Linux system administration?
Set up lab environment (VirtualBox/VMware), practice with real scenarios, follow tutorials, obtain certifications (LFCS, RHCSA), contribute to open source, and learn from production issues.
How do I manage multiple servers efficiently?
Use configuration management tools (Ansible, Puppet, Chef), centralized logging (ELK stack), monitoring dashboards, SSH key management, jump servers, and automation scripts for repetitive tasks.
What logs should I monitor regularly?
Essential logs: /var/log/auth.log (authentication), /var/log/syslog (system), application logs, web server logs, database logs. Use log aggregation tools for centralized monitoring.
How do I recover from a failed system update?
Boot from previous kernel (GRUB menu), use recovery mode, check logs for errors, roll back problematic packages, restore from backup if necessary. Always backup before major updates.
Conclusion
Effective system administration requires continuous learning, proactive monitoring, proper security practices, and regular maintenance. Master these fundamentals to build reliable, secure, and high-performing Linux infrastructure. Practice in lab environments, automate repetitive tasks, and always maintain comprehensive backups.
These skills form the foundation – continue expanding your knowledge with specialized areas like containerization, cloud platforms, and infrastructure as code to advance your sysadmin career.
Was this article helpful?
About Ramesh Sundararamaiah
Red Hat Certified Architect
Expert in Linux system administration, DevOps automation, and cloud infrastructure. Specializing in Red Hat Enterprise Linux, CentOS, Ubuntu, Docker, Ansible, and enterprise IT solutions.