Seville, Spain
Seville, Spain
+(34) 624 816 969
Table of contents [Show]
Hardening Linux servers is a critical process to reduce vulnerabilities and ensure system integrity. Combined with periodic maintenance, it helps maintain performance and security in the long term. In this practical guide, we will cover best practices for hardening and maintenance, from initial configuration to task automation.

Keeping the system updated is the first step. Use apt update && apt upgrade (Debian/Ubuntu) or yum update (RHEL/CentOS). Configure automatic security updates with unattended-upgrades.
/etc/ssh/sshd_config, set PermitRootLogin no.adduser usuario && usermod -aG sudo usuario.
Configure ufw (Uncomplicated Firewall) or iptables. Example with UFW:
ufw default deny incoming
ufw default allow outgoing
ufw allow ssh
ufw enableFor more complex environments, consider fail2ban to protect against brute force attacks. As we saw in our article on code review with AI, automation is key; similarly, automating security with tools like ansible can save time.
Edit /etc/sysctl.conf to disable IP forwarding, mitigate network attacks, etc.:
net.ipv4.ip_forward=0
net.ipv4.conf.all.accept_source_route=0
kernel.exec-shield=1Disable non-essential services with systemctl disable servicio. Check open ports with ss -tuln.

Configure logrotate to prevent logs from filling the disk. Monitor with journalctl or tools like Nagios. In the category Automation and Observability you will find more resources.
Automate backups with rsync or duplicity. Verify backup integrity periodically.
Create a hardening script that executes all the above configurations. For example, a bash script that configures SSH, firewall, sysctl, etc. You can integrate it with configuration management tools like Ansible.
Hardening and maintenance of Linux servers is an ongoing process. Implement these practices from the start and review them periodically. For more guides, visit our category Guides and Tutorials.