Table of Contents
- System Updates & Patching
- User & Access Management
- Network Security
- File System Security
- Service Hardening
- Logging & Monitoring
- Kernel Security
- Physical Security
- Third-Party Software
- Incident Response Plan
- Conclusion
- References
1. System Updates & Patching
Outdated software is one of the most common entry points for attackers. Regular updates patch known vulnerabilities in the OS, kernel, and applications.
Key Steps:
- Enable Automatic Updates: Use tools like
unattended-upgrades(Debian/Ubuntu) ordnf-automatic(RHEL/CentOS) to automate security patches.# Debian/Ubuntu: Install and configure unattended-upgrades sudo apt install unattended-upgrades sudo dpkg-reconfigure -plow unattended-upgrades - Update Kernel Regularly: The kernel is the core of the OS; outdated kernels are prone to exploits (e.g., Spectre/Meltdown). Use
apt upgrade(Debian) oryum update kernel(RHEL). - Verify Package Integrity: Use
debsums(Debian) orrpm -V(RHEL) to check for tampered files:sudo debsums -c # List corrupted Debian packages
2. User & Access Management
Misconfigured user accounts are a major risk. Limit privileges and enforce strict access controls.
Key Steps:
- Disable Root Login: Prevent direct root access via SSH and physical consoles. Use
sudofor administrative tasks.- Edit
/etc/ssh/sshd_config:PermitRootLogin no - Restrict physical root login: Set
rootshell to/usr/sbin/nologinin/etc/passwd.
- Edit
- Enforce Strong Passwords: Use PAM (Pluggable Authentication Modules) to enforce complexity.
- Edit
/etc/pam.d/common-password(Debian) or/etc/pam.d/system-auth(RHEL):password requisite pam_pwquality.so retry=3 minlen=12 ucredit=-1 lcredit=-1 dcredit=-1 ocredit=-1 - Set password expiration:
chage -M 90 -W 14 <username>(force change every 90 days, warn 14 days prior).
- Edit
- SSH Hardening:
- Use SSH keys instead of passwords:
ssh-keygen(client),ssh-copy-id user@server(copy key to server). - Disable password authentication: Edit
/etc/ssh/sshd_config:PasswordAuthentication no - Limit SSH users:
AllowUsers alice [email protected]/24(only allow Alice and Bob from 192.168.1.0 subnet). - Change default SSH port (e.g.,
Port 2222) to reduce brute-force attempts.
- Use SSH keys instead of passwords:
- Two-Factor Authentication (2FA): Add 2FA for SSH using
libpam-google-authenticator:sudo apt install libpam-google-authenticator google-authenticator # Run as user to generate QR code- Edit
/etc/pam.d/sshd:auth required pam_google_authenticator.so
- Edit
3. Network Security
Limit exposure by securing network interfaces and blocking unnecessary traffic.
Key Steps:
- Enable a Firewall: Use
ufw(simple) oriptables(advanced) to filter traffic.# UFW example: Allow SSH (port 2222) and HTTP/HTTPS, deny all else sudo ufw default deny incoming sudo ufw default allow outgoing sudo ufw allow 2222/tcp sudo ufw allow 80/tcp sudo ufw allow 443/tcp sudo ufw enable - Close Unused Ports: Identify open ports with
ss -tulnornetstat -tuln, then disable associated services. - Disable IPv6 (If Unused): Edit
/etc/sysctl.confto block IPv6:
Runnet.ipv6.conf.all.disable_ipv6 = 1 net.ipv6.conf.default.disable_ipv6 = 1sudo sysctl -pto apply. - Use Secure Protocols: Replace insecure protocols (Telnet, FTP, HTTP) with SSH, SFTP, or HTTPS. For example, configure Nginx/Apache to redirect HTTP to HTTPS.
4. File System Security
Protect critical files and directories from tampering or unauthorized access.
Key Steps:
- Set Proper Permissions: Use
chmodandchownto restrict access. For example:sudo chmod 600 /etc/shadow # Only root can read/write shadow passwords sudo chown root:root /etc/sudoers # Ensure sudoers is owned by root - Immutable Files: Mark critical files (e.g.,
/etc/passwd,/etc/ssh/sshd_config) as immutable withchattrto prevent tampering:
(Usesudo chattr +i /etc/passwdchattr -ito revert.) - Encrypt File Systems: Use LUKS (Linux Unified Key Setup) to encrypt disks/partitions. For existing systems, encrypt
/homeor useecryptfs. - Mount Options: Secure
/tmp,/var/tmp, and/dev/shmby addingnoexec,nosuid,nodevto/etc/fstab:tmpfs /tmp tmpfs defaults,noexec,nosuid,nodev 0 0
5. Service Hardening
Disable unnecessary services and secure critical ones (e.g., web servers, databases).
Key Steps:
- Disable Unused Services: Stop and mask services not needed (e.g.,
cups,telnetd):sudo systemctl stop cups sudo systemctl disable cups sudo systemctl mask cups # Prevent accidental startup - Harden Web Servers:
- For Nginx: Edit
/etc/nginx/nginx.confto disable server tokens (server_tokens off;) and enable HTTPS with strong ciphers. - For Apache: Use
mod_securityWAF and restrictServerSignaturein/etc/apache2/conf-available/security.conf.
- For Nginx: Edit
- Isolate Services: Use
chrootjails, Docker containers, or systemd-nspawn to limit service access to the host system.
6. Logging & Monitoring
Detect breaches early with robust logging and real-time alerts.
Key Steps:
- Centralized Logging: Aggregate logs from multiple servers using
rsyslogorsyslog-ng. Forward logs to a central server for analysis. - Audit System Activity: Use
auditdto monitor file access, user actions, and process execution:
View logs withsudo apt install auditd sudo auditctl -w /etc/passwd -p wa -k passwd_changes # Log writes/appends to passwdausearch -k passwd_changes. - Log Rotation: Configure
logrotateto prevent log files from consuming disk space (default in most distros). - Real-Time Alerts: Use
fail2banto block brute-force attacks on SSH/HTTP:
Editsudo apt install fail2ban sudo cp /etc/fail2ban/jail.conf /etc/fail2ban/jail.localjail.localto set bantime and thresholds (e.g., ban IPs after 5 failed SSH attempts).
7. Kernel Security
Secure the kernel to mitigate low-level exploits.
Key Steps:
- Configure
sysctlParameters: Edit/etc/sysctl.confto enable security-focused kernel settings:# Prevent IP spoofing net.ipv4.conf.all.rp_filter = 1 # Block SYN floods net.ipv4.tcp_syncookies = 1 # Disable ICMP redirects net.ipv4.conf.all.accept_redirects = 0 - Enable AppArmor/SELinux:
- SELinux (RHEL/CentOS): Set to
enforcingmode in/etc/selinux/config. - AppArmor (Debian/Ubuntu): Enable profiles for critical services (e.g.,
apache2,sshd):sudo aa-enforce /etc/apparmor.d/usr.sbin.sshd
- SELinux (RHEL/CentOS): Set to
- Disable Unused Kernel Modules: Blacklist risky modules (e.g., USB storage) in
/etc/modprobe.d/blacklist.conf:blacklist usb-storage
8. Physical Security
Even secure systems are vulnerable if physical access is unrestricted.
Key Steps:
- BIOS/UEFI Password: Set a password to prevent unauthorized changes to boot settings.
- Disk Encryption: Use LUKS to encrypt the entire disk. During OS installation, select “encrypt disk” or use
cryptsetuppost-install. - Secure Boot: Enable Secure Boot in BIOS/UEFI to block unsigned bootloaders (prevents rootkits).
9. Third-Party Software
Third-party apps (e.g., Docker, Node.js) can introduce vulnerabilities.
Key Steps:
- Vet Sources: Only install software from official repos or trusted PPAs. Avoid random
.deb/.rpmfiles. - Minimize Dependencies: Use
apt autoremoveoryum autoremoveto uninstall unused packages. - Audit Regularly: Scan for outdated software with
apt list --upgradable(Debian) oryum check-update(RHEL).
10. Incident Response Plan
Prepare for breaches with a documented plan.
Key Steps:
- Backup Data: Use
rsync,borgbackup, or cloud backups (e.g., AWS S3) with encryption. Test restores regularly. - Document Procedures: Outline steps to isolate affected systems, analyze logs, and notify stakeholders.
- Practice Drills: Simulate breaches to test response times and identify gaps.
Conclusion
Linux security hardening is an ongoing process, not a one-time task. Regularly audit your system (use tools like lynis or chkrootkit), stay updated on vulnerabilities (via CVE Details), and adapt your checklist to new threats. By following this guide, you’ll significantly reduce your attack surface and protect your data.