Security is not a single tool or a static configuration; it is an ongoing operational process. While open-source operating systems possess a robust, multi-user security architecture built directly into their foundation, leaving a server running with default settings still invites unauthorized access, automated brute-force attacks, and malware propagation.
Securing a system requires applying the principle of Defense in Depth—layering multiple security controls so that if one security barrier fails, secondary defenses prevent complete system compromise.
Every system administrator managing Linux environments should enforce these essential security configurations.
1. Enforce Strong SSH Hardening Policies
The Secure Shell (SSH) daemon is typically the primary remote administration vector, making it a constant target for automated port scanners.
Essential SSH Security Settings (/etc/ssh/sshd_config):
- Disable Password-Based Authentication: Force all users to authenticate using cryptographic SSH key pairs (Ed25519 or RSA 4096-bit).
PasswordAuthentication no - Disable Root Shell Logins: Prevent attackers from targeting the administrative account directly. Administrators must log in via a standard user account and escalate privileges using
sudo.PermitRootLogin no - Restrict Allowed Users: Explicitly define which user accounts are permitted to establish SSH connections.
AllowUsers adminuser devopsops
2. Implement the Principle of Least Privilege with sudo
Avoid logging into servers as the root user for day-to-day administrative tasks. Instead, assign permissions dynamically using the sudo (Superuser Do) framework.
- Audit Sudoers Configuration: Edit permissions exclusively with
visudoto prevent syntax errors that could lock you out of system access. - Restrict Unnecessary Root Access: Grant users access only to specific commands rather than blanket administrative rights whenever possible.
- Log Administrative Actions: Ensure all commands executed through
sudoare logged to/var/log/auth.logor captured byjournalctlfor security auditing.
3. Configure Network Boundaries with Firewalls
A server should only expose ports required for active, authorized services. All other incoming ports must remain closed by default.
Setting Up UFW (Uncomplicated Firewall)
# Block all incoming traffic by default
sudo ufw default deny incoming
# Allow all outgoing connection requests
sudo ufw default allow outgoing
# Allow necessary incoming service ports
sudo ufw allow 22/tcp comment 'SSH Access'
sudo ufw allow 80/tcp comment 'HTTP Web Traffic'
sudo ufw allow 443/tcp comment 'HTTPS Web Traffic'
# Enable rules
sudo ufw enable
For enterprise environments, utilize nftables or iptables to create precise traffic filtering rules based on source IP subnets.
4. Enable Mandatory Access Control (SELinux or AppArmor)
Traditional discretionary access controls (DAC)—such as file permissions chmod and chown—allow users and processes to modify permissions on assets they own. If a web application process running as www-data is compromised, an attacker gains access to everything that account can touch.
Mandatory Access Control (MAC) frameworks restrict process actions based on centralized security policies:
- SELinux (Red Hat / Fedora / CentOS family): Assigns security labels to processes, files, and network ports. Even if an attacker compromises a web daemon, SELinux prevents that process from reading unauthorized user home directories or executing arbitrary binaries.
- AppArmor (Ubuntu / Debian family): Uses program profiles to restrict capabilities and file paths individual applications are allowed to access.
# Check SELinux status on RHEL systems
sestatus
# Check AppArmor status on Ubuntu systems
sudo aa-status
Always keep MAC frameworks set to Enforcing mode in production rather than disabling them.
5. Automate Patch Management and Intrusion Prevention
Unpatched software vulnerabilities represent one of the largest attack vectors in enterprise environments.
- Automate Security Updates: Configure tools like
unattended-upgrades(Debian/Ubuntu) ordnf-automatic(RHEL/Fedora) to apply critical security patches automatically. - Deploy Fail2ban for Brute-Force Defense: Automate log monitoring to block malicious traffic dynamically. Fail2ban scans authentication logs and temporarily or permanently bans IP addresses exhibiting suspicious behavior (such as multiple failed SSH login attempts).
# Check Fail2ban jail status
sudo fail2ban-client status sshd
Comprehensive Security Audit Checklist
┌───────────────────────────────────────┐
│ Layered Defense Architecture │
└──────────────────┬────────────────────┘
│
┌──────────────────┬─────────────┴────────────┬──────────────────┐
▼ ▼ ▼ ▼
[ Access Control ] [ Network Shield ] [ Access Limits ] [ Monitoring ]
• SSH Key Auth • UFW / Nftables • Least Privilege • Fail2ban
• Root Login Off • Closed Ports • SELinux/AppArmor • Audit Logs
By applying SSH hardening, minimal permission policies, strict firewall rules, kernel-level access controls, and automated log monitoring, system administrators can establish a resilient environment capable of withstanding modern security threats.