Hardening the linux server or cenos 5/6.2
Introduction
Linux server hardening is the process of securing a Linux operating system by minimizing its attack surface and reducing vulnerabilities. Older operating systems such as CentOS 5 and CentOS 6.2 are no longer supported, making them especially vulnerable to modern cyber threats.
Although upgrading to a supported operating system is strongly recommended, many organizations still maintain legacy servers for business-critical applications. In such cases, proper hardening becomes essential.
This guide covers practical security measures for hardening CentOS 5 and CentOS 6.2 servers.
Essential Hardening Steps
1. Update the System
Install the latest available packages from the configured repositories.
yum clean all yum update -y
2. Remove Unnecessary Packages
Uninstall services that are not required, such as Telnet, FTP, and other legacy applications.
yum remove telnet ftp rsh
3. Disable Unused Services
Disable services that are not needed to reduce the attack surface.
chkconfig cups off chkconfig bluetooth off service cups stop
4. Secure SSH Access
Edit /etc/ssh/sshd_config and apply these settings:
PermitRootLogin no PasswordAuthentication no MaxAuthTries 3 Protocol 2
Restart the SSH service:
service sshd restart
5. Configure the Firewall
Allow only the required ports using iptables.
iptables -A INPUT -p tcp --dport 22 -j ACCEPT iptables -A INPUT -p tcp --dport 80 -j ACCEPT iptables -A INPUT -p tcp --dport 443 -j ACCEPT
6. Use Strong Password Policies
- Enforce complex passwords.
- Lock inactive accounts.
- Disable unused user accounts.
7. Verify File Permissions
Protect sensitive files such as /etc/shadow and remove unnecessary world-writable permissions.
chmod 600 /etc/shadow
8. Enable Logging
Monitor system logs regularly to identify unauthorized access or suspicious activity.
Useful log files:
/var/log/messages/var/log/secure/var/log/cron
9. Enable SELinux
If supported by your environment, keep SELinux in Enforcing mode for additional protection.
getenforce
10. Perform Regular Backups
Back up important configuration files and verify that backup restoration works correctly.
tar -czvf etc-backup.tar.gz /etc
Best Practices
- Disable root SSH login.
- Use SSH key authentication instead of passwords.
- Keep only essential services running.
- Review user accounts regularly.
- Monitor logs for suspicious activity.
- Restrict open network ports.
- Schedule regular backups.
- Plan to migrate legacy systems to a supported Linux distribution.
Conclusion
Hardening CentOS 5 and CentOS 6.2 servers is essential for protecting legacy systems from security threats. While these operating systems are no longer supported, applying basic security measures such as securing SSH, configuring firewalls, managing user access, enabling logging, and performing regular backups can significantly reduce risk. For long-term security and compliance, migrating to a supported Linux distribution such as AlmaLinux, Rocky Linux, or Red Hat Enterprise Linux (RHEL) is strongly recommended.
