Lesson 12 — Linux Security Best Practices
Lesson 12 — Linux Security Best Practices
Section titled “Lesson 12 — Linux Security Best Practices”Lesson Overview
Section titled “Lesson Overview”Linux powers the majority of today’s cloud infrastructure, enterprise servers, Kubernetes clusters, and DevOps platforms.
Because Linux systems often host critical business applications and sensitive data, they are common targets for cyber attacks.
A secure Linux server isn’t achieved by installing an operating system alone—it requires proper configuration, regular maintenance, monitoring, and adherence to security best practices.
Whether you’re deploying an EC2 instance in AWS, managing a Kubernetes worker node, or administering enterprise Linux servers, security must be integrated into every stage of the system lifecycle.
In this lesson, you’ll learn practical techniques used by Linux administrators and security engineers to harden Linux systems and reduce security risks.
Learning Objectives
Section titled “Learning Objectives”After completing this lesson, you will be able to:
- Understand Linux system hardening.
- Secure user accounts and authentication.
- Configure SSH securely.
- Manage Linux firewalls.
- Keep Linux systems updated.
- Monitor logs and system activity.
- Apply enterprise Linux security best practices.
What is Linux Hardening?
Section titled “What is Linux Hardening?”Linux Hardening is the process of reducing the attack surface of a Linux system by implementing security controls and following best practices.
Hardening helps:
- Prevent unauthorized access.
- Reduce vulnerabilities.
- Improve system resilience.
- Meet compliance requirements.
- Protect sensitive data.
Why Linux Security Matters
Section titled “Why Linux Security Matters”An insecure Linux server may lead to:
- Unauthorized access
- Data theft
- Malware infections
- Ransomware
- Privilege escalation
- Service disruption
- Regulatory violations
Strong security practices significantly reduce these risks.
Principle of Least Privilege
Section titled “Principle of Least Privilege”Every user should have only the permissions required to perform their job.
Example:
Developer
↓
Application Directory
✓ Access
↓
System Configuration
✗ No AccessNever grant administrator privileges unless absolutely necessary.
Secure User Accounts
Section titled “Secure User Accounts”Best practices include:
- Create individual user accounts.
- Disable unused accounts.
- Enforce strong passwords.
- Use Multi-Factor Authentication (MFA) where supported.
- Regularly review user permissions.
- Avoid shared accounts.
User management is the foundation of Linux security.
Avoid Direct Root Login
Section titled “Avoid Direct Root Login”The root account has unrestricted access.
Instead of logging in directly as root:
sudoExample:
sudo apt updateUsing sudo provides better accountability and auditing.
Secure SSH Access
Section titled “Secure SSH Access”SSH is one of the most commonly targeted services.
Recommended practices:
- Disable root login.
- Use SSH key authentication.
- Disable password authentication when possible.
- Change the default SSH configuration only when required by organizational policy.
- Restrict access to trusted IP addresses.
- Enable MFA if supported.
- Use modern cryptographic algorithms.
Example configuration:
/etc/ssh/sshd_configRecommended settings:
PermitRootLogin no
PasswordAuthentication noRestart SSH after making changes.
sudo systemctl restart sshKeep Linux Updated
Section titled “Keep Linux Updated”Regular updates help protect systems from known vulnerabilities.
Ubuntu:
sudo apt update
sudo apt upgradeRed Hat:
sudo dnf upgradeAlways test updates in non-production environments before deploying to production.
Configure the Firewall
Section titled “Configure the Firewall”Limit unnecessary network access.
Ubuntu (UFW):
Enable firewall:
sudo ufw enableAllow SSH:
sudo ufw allow 22Allow HTTPS:
sudo ufw allow 443View firewall status:
sudo ufw statusEnterprise systems may use firewalld, nftables, or cloud-native firewall services.
Disable Unnecessary Services
Section titled “Disable Unnecessary Services”Every running service increases the attack surface.
List active services:
systemctl list-units --type=serviceDisable unused services:
sudo systemctl disable service-nameOnly run services that are required.
Secure File Permissions
Section titled “Secure File Permissions”Protect sensitive files.
Examples:
SSH Private Key:
600User Home Directory:
700Review permissions regularly.
Commands:
ls -la
chmod
chownEnable Logging
Section titled “Enable Logging”Logs provide valuable information during troubleshooting and security investigations.
View system logs:
journalctlAuthentication logs:
Ubuntu:
/var/log/auth.logRed Hat:
/var/log/secureMonitor logs regularly for suspicious activity.
Monitor Failed Login Attempts
Section titled “Monitor Failed Login Attempts”Failed authentication attempts may indicate brute-force attacks.
Example:
sudo journalctl -u sshOr review authentication logs using:
grep "Failed" /var/log/auth.logInvestigate repeated failures promptly.
Install Fail2Ban
Section titled “Install Fail2Ban”Fail2Ban helps protect against brute-force attacks.
Install:
sudo apt install fail2banEnable:
sudo systemctl enable fail2banStart:
sudo systemctl start fail2banFail2Ban automatically blocks IP addresses that repeatedly fail authentication.
Secure Password Policies
Section titled “Secure Password Policies”Strong passwords should include:
- Uppercase letters
- Lowercase letters
- Numbers
- Special characters
- Minimum recommended length of 12–16 characters
Avoid:
- Dictionary words
- Personal information
- Reused passwords
Use SSH Keys
Section titled “Use SSH Keys”Generate an SSH key pair:
ssh-keygenCopy the public key:
ssh-copy-id user@serverSSH keys provide stronger security than passwords and are commonly used in cloud environments.
Monitor Running Processes
Section titled “Monitor Running Processes”Display running processes:
ps -efInteractive monitoring:
topor
htopUnexpected processes should be investigated.
Monitor Open Network Ports
Section titled “Monitor Open Network Ports”Display listening ports:
ss -tulnReview services listening on the network and close unnecessary ports.
Secure Software Installation
Section titled “Secure Software Installation”Install software only from trusted repositories.
Ubuntu:
sudo apt install package-nameAvoid downloading random installation scripts from untrusted websites.
Regular Backups
Section titled “Regular Backups”Security also includes recoverability.
Backup:
- Configuration files
- Databases
- Application data
- User data
Regularly test restoration procedures.
Linux Security in Cloud Computing
Section titled “Linux Security in Cloud Computing”Cloud providers provide additional security controls.
AWS:
- Security Groups
- IAM Roles
- Systems Manager
- AWS Inspector
- AWS GuardDuty
Azure:
- Network Security Groups
- Microsoft Defender for Cloud
- Azure Policy
Google Cloud:
- Cloud Armor
- Security Command Center
- Identity and Access Management (IAM)
Linux hardening should complement cloud-native security controls.
Linux Security in Cybersecurity
Section titled “Linux Security in Cybersecurity”Security teams perform activities such as:
- Vulnerability assessments
- Log analysis
- File integrity monitoring
- User auditing
- Malware detection
- Incident response
- Compliance assessments
Linux security is a core skill for SOC Analysts, Incident Responders, and Penetration Testers.
Common Security Commands
Section titled “Common Security Commands”Current user:
whoamiDisplay login history:
lastDisplay failed logins:
lastbView running processes:
ps -efView listening ports:
ss -tulnView firewall status:
sudo ufw statusView service status:
systemctl status sshDisplay authentication logs:
journalctl -u sshReal-World Example
Section titled “Real-World Example”A new Linux web server is deployed in AWS.
The administrator performs the following hardening steps:
Create Administrator Account
↓
Disable Root Login
↓
Configure SSH Keys
↓
Enable Firewall
↓
Install Security Updates
↓
Install Fail2Ban
↓
Review File Permissions
↓
Enable Logging
↓
Monitor SystemThis baseline hardening significantly improves the server’s security posture.
Best Practices
Section titled “Best Practices”As a Linux administrator:
- Apply security updates regularly.
- Follow the Principle of Least Privilege.
- Use SSH keys instead of passwords whenever possible.
- Disable unnecessary services.
- Restrict network access using firewalls.
- Monitor authentication logs.
- Audit privileged accounts.
- Perform regular security reviews and backups.
Security should be treated as an ongoing process rather than a one-time task.
Key Takeaways
Section titled “Key Takeaways”After completing this lesson, you should understand:
- Linux system hardening.
- Secure user management.
- SSH security best practices.
- Firewall configuration.
- Software update management.
- Log monitoring and auditing.
- Enterprise Linux security best practices.
Summary
Section titled “Summary”Linux security is one of the most important responsibilities of every system administrator, cloud engineer, and cybersecurity professional.
By implementing strong authentication, securing remote access, managing permissions, applying updates, monitoring logs, and reducing the attack surface, you can significantly improve the security and reliability of Linux systems.
These practices form the foundation of enterprise Linux administration and will be used throughout your cloud, DevOps, Kubernetes, and cybersecurity career.
Next Lesson
Section titled “Next Lesson”➡️ Lesson 13 — Linux Administration & Troubleshooting
In the next lesson, you’ll learn how to troubleshoot Linux systems, diagnose performance issues, analyze logs, monitor CPU, memory, storage, and networking, and follow structured troubleshooting methodologies used by enterprise Linux administrators.