How to Secure a Linux Server: Essential Steps for Beginners
Securing a Linux server is critical to protect your data and applications from unauthorized access and attacks. This tutorial covers the fundamental steps every administrator should implement—from initial setup to ongoing maintenance. By following these practices, you can significantly reduce your server’s attack surface.
Start by updating your system packages. Outdated software is a common entry point for attackers. Run sudo apt update && sudo apt upgrade (on Debian/Ubuntu) or the equivalent for your distribution. Enable automatic security updates to stay protected without manual intervention.
Harden SSH Access
SSH is a primary attack vector. Disable root login by setting PermitRootLogin no in /etc/ssh/sshd_config. Use SSH key authentication instead of passwords—generate a key pair with ssh-keygen and add the public key to ~/.ssh/authorized_keys. Change the default port (22) to a non-standard one to reduce automated scans. Restart the SSH service after changes.
Configure a Firewall with UFW
A firewall blocks unwanted traffic. Enable UFW (sudo ufw enable) and set default policies to deny incoming and allow outgoing. Allow only necessary services: sudo ufw allow ssh (or your custom SSH port), sudo ufw allow http, etc. Verify rules with sudo ufw status verbose. For extra protection, use fail2ban to ban IPs after repeated failed login attempts.
Implement Regular Audits and User Management
Create separate user accounts for each administrator and grant privileges via sudo groups (e.g., usermod -aG sudo username). Regularly review active users with who and last. Monitor logs in /var/log/auth.log for suspicious activity. Set up a cron job to run lynis (a security auditing tool) weekly and review its recommendations.
Applying these steps gives you a solid security baseline. Stay proactive by keeping software updated, monitoring logs, and limiting access. A secure server is an ongoing practice—start with these essentials and build from there.