Most breaches I see in tickets start the same way: default SSH ports, weak passwords, or services nobody remembered were running. The fix is boring and methodical, which is why it works.
This checklist walks through seven practical steps to harden a Linux server in 2026. Nothing here is new or exciting—it's the stuff that stops attacks before they start. If you run VPS instances, dedicated servers, or cPanel boxes, these are the baseline controls you should have in place.
1. Configure your firewall to deny by default
Most distributions ship with iptables or nftables available, but the default policy is usually ACCEPT. That's backward.
Set your INPUT chain to DROP, then explicitly allow only what you need:
# Using iptables
iptables -P INPUT DROP
iptables -P FORWARD DROP
iptables -P OUTPUT ACCEPT
# Allow loopback
iptables -A INPUT -i lo -j ACCEPT
# Allow established connections
iptables -A INPUT -m conntrack --ctstate ESTABLISHED,RELATED -j ACCEPT
# Allow SSH (change port if you've moved it)
iptables -A INPUT -p tcp --dport 22 -j ACCEPT
# Allow HTTP/HTTPS
iptables -A INPUT -p tcp --dport 80 -j ACCEPT
iptables -A INPUT -p tcp --dport 443 -j ACCEPT
# Save rules
iptables-save > /etc/iptables/rules.v4
For firewalld (CentOS, AlmaLinux, Rocky):
firewall-cmd --set-default-zone=drop
firewall-cmd --zone=public --add-service=ssh --permanent
firewall-cmd --zone=public --add-service=http --permanent
firewall-cmd --zone=public --add-service=https --permanent
firewall-cmd --reload
Audit your open ports quarterly. I've found mail servers with MySQL exposed to the internet, WordPress boxes with Redis listening on 0.0.0.0, and VPS instances running VNC that nobody remembered setting up.
2. Harden SSH and disable password authentication
SSH is the front door. Make it a pain to kick in.
Edit /etc/ssh/sshd_config and apply these changes:
# Disable root login
PermitRootLogin no
# Disable password authentication
PasswordAuthentication no
ChallengeResponseAuthentication no
# Use key-based auth only
PubkeyAuthentication yes
# Change the default port (optional but effective)
Port 2200
# Limit login grace time
LoginGraceTime 30
# Disable X11 forwarding if you don't use it
X11Forwarding no
# Allow only specific users
AllowUsers yourusername
Restart SSH after testing your key login in a second session:
systemctl restart sshd
Before you close that second session, verify you can log in with your key. I've locked myself out twice by skipping that step.
Consider fail2ban or sshguard to block brute-force attempts automatically. Set the ban time long enough to matter—an hour minimum.
3. Patch weekly, automate where possible
Unpatched software is the easiest door in. Most hosting breaches I've handled traced back to known CVEs with fixes already available.
On Debian/Ubuntu, enable unattended upgrades for security updates:
apt install unattended-upgrades
dpkg-reconfigure --priority=low unattended-upgrades
Edit /etc/apt/apt.conf.d/50unattended-upgrades to control what gets updated automatically. I enable security updates and leave version upgrades manual.
For RHEL-based systems, use dnf-automatic:
dnf install dnf-automatic
systemctl enable --now dnf-automatic.timer
Set a calendar reminder to check manually once a week. Automated updates handle the routine stuff, but kernel updates and service restarts need human review.
If you run cPanel, WHM has a built-in update system under "Update Preferences." Enable automatic updates for cPanel and OS security patches separately.
4. Run only what you need
Every running service is another attack surface. Audit what's listening:
ss -tulnp
You'll see TCP and UDP sockets with the process names. Anything you don't recognize or need should be stopped and disabled.
Common things to remove or disable: - Sendmail or Postfix if you use a third-party SMTP relay - Apache if you run Nginx, or vice versa - FTP daemons (use SFTP instead) - Telnet, rsh, rlogin (these should never be installed)
systemctl disable servicename
systemctl stop servicename
I've seen WordPress sites running Memcached with no authentication, listening on 0.0.0.0. Easy amplification attack vector. If you don't need it, kill it.
5. Enforce least privilege with user permissions
Don't run applications as root. Create dedicated system users with minimal permissions.
For a web app:
useradd -r -s /bin/false -d /var/www/myapp myapp
chown -R myapp:myapp /var/www/myapp
For database access, create specific MySQL or PostgreSQL users with grants limited to the databases they actually need. Never give GRANT ALL.
Use sudo for administrative tasks instead of logging in as root. Configure /etc/sudoers to allow specific commands without a password if you need automation:
yourusername ALL=(ALL) NOPASSWD: /usr/bin/systemctl restart nginx
Be stingy with sudo access. Every user with sudo is a potential escalation path.
6. Implement file integrity monitoring
You need to know when system files change. I use AIDE (Advanced Intrusion Detection Environment) on most boxes.
Install and initialize:
apt install aide
aideinit
mv /var/lib/aide/aide.db.new /var/lib/aide/aide.db
Run a check:
aide --check
Schedule daily checks via cron:
0 3 * * * /usr/bin/aide --check | mail -s "AIDE report" [email protected]
AIDE will alert you when binaries, configs, or system libraries change. False positives happen after legitimate updates, so review the output instead of ignoring it.
For WordPress or application-level monitoring, tools like Wordfence or Sucuri watch for malicious file changes in web directories.
7. Apply zero-trust principles to network architecture
Zero trust means never assume a connection is safe just because it's "internal." Segment your network, require authentication everywhere, and log everything.
Practical steps:
- Use VLANs or VPC subnets to isolate database servers, application servers, and admin interfaces.
- Require VPN access for administrative panels (cPanel/WHM, Plesk, webmail admin).
- Disable direct database access from the internet. Bind MySQL to 127.0.0.1 or a private network interface.
- Use TLS for internal service-to-service communication when possible.
- Enable audit logging for SSH sessions with
auditd.
Example MySQL bind config in /etc/mysql/my.cnf:
[mysqld]
bind-address = 127.0.0.1
For cPanel servers, restrict WHM access by IP in "Host Access Control" under WHM Security Center.
Log aggregation helps here. Ship logs to a central location (syslog server, ELK stack, or a managed service) so an attacker can't just delete local logs after a breach.
What if you inherit an unsecured server?
Start with SSH and the firewall. Those two steps stop the automated scans that hit every public IP.
Then audit running services and patch everything. The rest can happen over the next week as you document what the server actually does.
Don't try to apply all seven steps in one maintenance window. You'll miss something and lock yourself out or break a dependency. Do it methodically, test each change, and keep that second SSH session open.
How often should I rotate SSH keys?
Rotate when someone with access leaves or when you suspect a key might be compromised. Annual rotation is reasonable for team environments; static keys are fine for single-admin setups if the private key is well-protected.
Should I change the SSH port or is that just security by obscurity?
It's obscurity, but it works. Changing the port eliminates 99% of automated brute-force noise in your logs. You still need key-based auth and fail2ban, but a non-standard port buys you time and reduces log clutter.
Do I need a WAF if I already have a firewall?
A network firewall works at layer 3/4. A web application firewall inspects HTTP traffic for SQL injection, XSS, and other app-layer attacks. They solve different problems. If you run WordPress or any CMS, a WAF (Cloudflare, Sucuri, or mod_security) is worth it.
How do I test if my firewall rules are actually working?
Scan your server from an external machine using nmap. You should see only the ports you explicitly opened. Close any extras you find.
What to check first
If you do nothing else, lock down SSH and close unused ports. Those two steps prevent most opportunistic attacks.
The rest of the checklist matters, but it's incremental. Firewall and SSH hardening are the foundation. Get those right first, then build out patch automation, service reduction, and zero-trust segmentation as you have time.
Security isn't a one-time project. It's a cadence: weekly patching, quarterly audits, and immediate response when you see something weird in the logs. Do the boring work consistently and you won't end up in my ticket queue.
