A fresh server is a soft target. Default configurations prioritize ease of use over security, which means SSH accepts passwords, the firewall allows everything, and kernel parameters let local processes exhaust resources. I walk through twelve hardening settings you can apply in one sitting—no reboot required for most of them.
This checklist assumes a Debian or RHEL-based distribution with root or sudo access. Each step includes the command, the config file, and what it actually does.
1. Disable SSH root login
Root login over SSH is the most common brute-force target. Disable it and force attackers to guess both a username and password.
Edit /etc/ssh/sshd_config:
PermitRootLogin no
Restart SSH:
systemctl restart sshd
If you lock yourself out, you'll need console access through your hosting panel. Test your sudo user first.
2. Enforce SSH key authentication
Passwords can be brute-forced. Keys cannot. Disable password authentication entirely once you've uploaded your public key to ~/.ssh/authorized_keys.
In /etc/ssh/sshd_config:
PasswordAuthentication no
PubkeyAuthentication yes
ChallengeResponseAuthentication no
Restart SSH again. From now on, only clients with the matching private key can connect.
3. Change the default SSH port
Port 22 gets hammered by bots. Moving SSH to a high port (above 1024) cuts automated scans by more than half in my experience. It's not real security, but it drops log noise and saves CPU cycles.
In /etc/ssh/sshd_config:
Port 2849
Restart SSH, then update your firewall rule (covered below) and reconnect using ssh -p 2849 user@host.
4. Set SSH idle timeout
An idle SSH session is a privilege escalation waiting to happen if someone walks away from their terminal. Drop connections after fifteen minutes of inactivity.
In /etc/ssh/sshd_config:
ClientAliveInterval 300
ClientAliveCountMax 2
The server sends a keepalive every 300 seconds. After two missed responses (ten minutes of true silence), the session closes.
5. Install and configure a firewall
Most distributions ship with iptables or nftables, but managing raw rules is error-prone. Use ufw on Debian/Ubuntu or firewalld on RHEL/CentOS.
For ufw:
apt install ufw
ufw default deny incoming
ufw default allow outgoing
ufw allow 2849/tcp # your SSH port
ufw allow 80/tcp
ufw allow 443/tcp
ufw enable
For firewalld:
yum install firewalld
systemctl start firewalld
systemctl enable firewalld
firewall-cmd --permanent --add-port=2849/tcp
firewall-cmd --permanent --add-service=http
firewall-cmd --permanent --add-service=https
firewall-cmd --reload
Verify with ufw status or firewall-cmd --list-all. Only the ports you explicitly allow will accept inbound traffic.
6. Disable unused network services
Every listening service is an attack surface. Find what's running:
ss -tulpn
You'll see a list of open ports and the processes bound to them. If you spot Avahi (mDNS), CUPS (printing), or RPC services you don't need, stop and disable them:
systemctl stop avahi-daemon
systemctl disable avahi-daemon
Repeat for anything not required by your application stack.
7. Enable automatic security updates
Patching manually is unrealistic for most teams. Automatic updates keep the kernel and critical packages current without you remembering to run apt upgrade.
On Debian/Ubuntu:
apt install unattended-upgrades
dpkg-reconfigure -plow unattended-upgrades
On RHEL/CentOS:
yum install yum-cron
systemctl start yum-cron
systemctl enable yum-cron
Edit /etc/yum/yum-cron.conf and set apply_updates = yes.
8. Harden kernel parameters with sysctl
The kernel exposes hundreds of tunables through /proc/sys. A few targeted changes mitigate common exploits and resource exhaustion attacks.
Create /etc/sysctl.d/99-hardening.conf:
# IP forwarding off unless you're routing
net.ipv4.ip_forward = 0
net.ipv6.conf.all.forwarding = 0
# Ignore ICMP redirects
net.ipv4.conf.all.accept_redirects = 0
net.ipv6.conf.all.accept_redirects = 0
# Ignore source-routed packets
net.ipv4.conf.all.accept_source_route = 0
net.ipv6.conf.all.accept_source_route = 0
# Enable TCP SYN cookies (SYN flood protection)
net.ipv4.tcp_syncookies = 1
# Log martian packets (spoofed, impossible addresses)
net.ipv4.conf.all.log_martians = 1
# Disable sending ICMP redirects
net.ipv4.conf.all.send_redirects = 0
# Enable reverse path filtering
net.ipv4.conf.all.rp_filter = 1
Apply immediately:
sysctl -p /etc/sysctl.d/99-hardening.conf
These settings persist across reboots. In production, I've seen SYN cookies alone stop small DDoS attempts cold.
9. Set file descriptor and process limits
A single user or compromised process can exhaust file descriptors or spawn thousands of processes, starving legitimate services. Set per-user limits in /etc/security/limits.conf:
* soft nofile 4096
* hard nofile 8192
* soft nproc 2048
* hard nproc 4096
The asterisk applies to all users except root. Restart your session for limits to take effect (check with ulimit -a).
10. Enable process accounting
Process accounting logs every command executed, including who ran it and when. That audit trail is gold when you're investigating an incident.
Install the package:
apt install acct # Debian/Ubuntu
yum install psacct # RHEL/CentOS
Start and enable:
systemctl start acct
systemctl enable acct
Query logs with lastcomm or dump-acct. Logs rotate automatically.
11. Configure centralized logging
Local logs disappear if an attacker wipes /var/log. Send syslog to a remote server or a hosted service. For a quick remote setup, configure rsyslog to forward over TCP.
On the client, edit /etc/rsyslog.conf or create /etc/rsyslog.d/10-remote.conf:
*.* @@logserver.example.com:514
The @@ prefix uses TCP instead of UDP. Restart rsyslog:
systemctl restart rsyslog
On the log server, configure rsyslog to listen on port 514 and store logs by hostname. If you're already using a SIEM or log aggregator, point rsyslog there instead.
12. Install and configure fail2ban
Fail2ban watches log files for repeated authentication failures and automatically blocks the offending IP via firewall rules. It's the easiest way to stop SSH brute-force attempts.
Install:
apt install fail2ban
Create /etc/fail2ban/jail.local:
[DEFAULT]
bantime = 3600
findtime = 600
maxretry = 5
[sshd]
enabled = true
port = 2849 # match your SSH port
logpath = /var/log/auth.log
Start and enable:
systemctl start fail2ban
systemctl enable fail2ban
Check banned IPs with fail2ban-client status sshd. I've seen single servers with thousands of banned IPs after a few weeks online.
What to check after hardening
After applying these settings, verify that legitimate access still works. SSH in from a new terminal before closing your existing session. Check that your application can still bind to its ports and that the firewall isn't blocking expected traffic.
Run a basic Nmap scan against your public IP to confirm only your intended ports are open:
nmap -Pn -p 1-65535 your.server.ip
You should see only SSH (on your custom port), HTTP, HTTPS, and any application-specific ports you explicitly allowed.
Review /var/log/auth.log (Debian/Ubuntu) or /var/log/secure (RHEL/CentOS) for failed login attempts. If you see none from your own IP, fail2ban is working. If you see thousands from unknown IPs, your server is already under automated attack—and now protected.
Start with SSH and the firewall
If you only have time for two items today, do SSH key authentication and the firewall. Those two steps block the majority of opportunistic attacks and cut your auth log noise to almost nothing. The rest of the checklist hardens the OS and gives you visibility, but the perimeter is where most breaches start.
Once your baseline is solid, schedule quarterly reviews to check for new CVEs, rotate SSH keys, and prune firewall rules you no longer need.
![Server Security Hardening Checklist: 12 Settings [Solved]](/images/blog/server-security-hardening-checklist-12-settings-solved.jpg)