Securing your Linux server is crucial to protect it from unauthorized access and potential attacks. Here are some essential steps to harden your Linux server after installation:
1. Update Your Server
Ensure your server is up-to-date with the latest security patches:
For Debian-based distributions:
sudo apt update && sudo apt upgrade -yFor RHEL-based distributions:
sudo yum update -y2. Create a Non-Root User
It’s best practice to avoid using the root account for regular tasks. Create a new user and grant sudo privileges:
sudo adduser newusersudo usermod -aG sudo newuser3. Configure SSH
Make SSH more secure by implementing the following:
Disable root login:
sudo nano /etc/ssh/sshd_configPermitRootLogin noChange the default SSH port:
Port 2222Restart SSH service:
sudo systemctl restart sshd4. Set Up a Firewall
Configure a firewall to allow only necessary traffic. Use UFW (Uncomplicated Firewall) on Debian-based systems:
sudo ufw allow 2222/tcpsudo ufw enableFor RHEL-based systems, use firewalld:
sudo firewall-cmd --add-port=2222/tcp --permanentsudo firewall-cmd --reload5. Install Fail2Ban
Fail2Ban helps protect your server from brute-force attacks:
sudo apt install fail2ban -yCreate a local configuration file:
sudo cp /etc/fail2ban/jail.conf /etc/fail2ban/jail.localEdit the jail.local file to enable SSH protection:
sudo nano /etc/fail2ban/jail.local[sshd]
enabled = truesudo systemctl restart fail2ban6. Disable Unnecessary Services
Disable services that are not needed to minimize potential vulnerabilities:
sudo systemctl disable servicenamesudo systemctl stop servicename7. Install and Configure Auditd
Auditd is a user-space component to the Linux Auditing System. It provides insight into activities on your server:
sudo apt install auditd -ysudo systemctl start auditdsudo systemctl enable auditd8. Set Up Log Monitoring
Use a log monitoring tool like Logwatch or Logrotate to keep track of server activities:
sudo apt install logwatch -ysudo nano /etc/cron.daily/00logwatchAdd the following line to the file:
/usr/sbin/logwatch --output mail --mailto [email protected] --detail high9. Enable Automatic Security Updates
Ensure your system automatically installs security updates:
sudo apt install unattended-upgrades -ysudo dpkg-reconfigure --priority=low unattended-upgrades10. Regularly Review Security Settings
Regularly review and update your security settings and configurations to ensure your server remains secure.
By following these steps, you can significantly enhance the security of your Linux server, reducing the risk of unauthorized access and potential attacks.


