Linux Hardening Checklist: 10 Steps to Secure a Fresh Server
A brand-new Linux server feels clean and safe. It is neither. Default settings are built for convenience, not security — and automated bots scan the internet for fresh servers within minutes of them going online. Before you deploy anything, run through this hardening checklist.
1. Update Everything First
sudo apt update && sudo apt full-upgrade -y
A fresh image can be weeks behind on patches. Update before you do anything else, and enable automatic security updates so you do not fall behind again.
2. Create a Non-Root User and Disable Root SSH
adduser anonyusermod -aG sudo anony
Then in /etc/ssh/sshd_config, set PermitRootLogin no and restart SSH. Root should never log in directly — if an attacker guesses or steals a root password, there is no second barrier.
3. Switch to SSH Keys, Disable Password Login
# On your machinessh-copy-id anony@your-server
Then in sshd_config, set PasswordAuthentication no and restart SSH. Keys are far harder to brute-force than any password, and disabling password login shuts down the most common server attack entirely.
4. Change the SSH Port (Optional, Low Value)
Moving SSH off port 22 cuts log noise, but it is not real security — scanners find open ports in seconds. Do it if you like quieter logs, but never treat it as a substitute for keys and a firewall.
5. Enable the Firewall and Allow Only What You Need
sudo ufw default deny incomingsudo ufw default allow outgoingsudo ufw allow 22/tcpsudo ufw allow 80/tcpsudo ufw allow 443/tcpsudo ufw enable
Every open port is an attack surface. If a service is not needed, close its port.
6. Install Fail2ban
sudo apt install fail2bansudo systemctl enable --now fail2ban
Fail2ban watches your logs and temporarily bans IPs that fail logins repeatedly. It turns a brute-force attack into a series of short, useless bans.
7. Remove Unneeded Services
ss -tulpn
Look at what is listening. If you see services you did not install and do not need, stop and disable them with systemctl disable –now <service>. A service you never use cannot be exploited if it is not running.
8. Set Up Automatic Security Updates
sudo apt install unattended-upgradessudo dpkg-reconfigure -plow unattended-upgrades
Most breached servers were not hacked with a zero-day — they were hacked through a patch that sat uninstalled for months.
9. Lock Down File Permissions
System files should be owned by root and not world-writable. Check for dangerous permissions with:
find / -perm -4000 -type f 2>/dev/null # SUID binariesfind / -perm -o+w -type f 2>/dev/null # world-writable files
And never run chmod 777 to “fix” a problem — it hands every user and process full access to that file.
10. Back Up Before You Need It
A hardened server can still be breached. Regular, tested, off-server backups are the only recovery that always works. Automate them and test a restore at least once.
Make It a Habit
Hardening is not a one-time task. Re-run this checklist after every major change, and schedule a monthly review: updates applied, ports still minimal, logs checked for failed logins. Attackers automate their scanning — automate your defense the same way.
Only test systems you own or have written permission to test.



Comments
Post a Comment