sudo lynis audit system. Each step links to a full guide.
Before you start
- You need root access or a user with
sudo. Commands below usesudo; if you are logged in as root you can leave it out. - Take a snapshot or backup before you change SSH or the firewall. See schedule and restore backups.
- Know how to reach your server if SSH stops working. On a VPS use the VNC console or rescue mode. On a dedicated server, open a ticket if you need console access.
- Use a supported release. Ubuntu 18.04 / 20.04, Debian 10 / 11 and CentOS 7 / Stream 8 no longer get regular security updates. Rebuild on a current release instead of hardening an old one.
What should a Linux server hardening checklist include?
How to harden SSH quickly
SSH is the service attackers target most. Once your key login works, put your SSH settings in one drop-in file. A drop-in file is a small file in/etc/ssh/sshd_config.d/ that the main config reads first.
1
Confirm your key login works
Log in with your SSH key as your sudo user, not as root. Keep this session open.
2
Create the drop-in file
alex with your user name:3
Test the configuration
4
Restart SSH
- Ubuntu / Debian
- AlmaLinux / Rocky
5
Test from a second session
Open a new terminal and log in again. Close the first session only when this works.
sshd uses the first value it finds for each setting, so a file in sshd_config.d/ overrides the same setting further down in /etc/ssh/sshd_config (sshd_config manual).
Which firewall should I use?
If you use Docker, read the note about published ports in the UFW guide first. You can also filter traffic before it reaches your VPS in the firewall panel.
How to check which services are listening
Every program that listens on a public address can be reached from the internet unless your firewall blocks it.127.0.0.1 means only the server itself can connect. 0.0.0.0 or [::] means every network interface. Stop and disable services you do not use:
How to audit your server with Lynis
Lynis is a free auditing tool that checks hundreds of settings and gives you a hardening score with suggestions.- Ubuntu / Debian
- AlmaLinux / Rocky
How to keep the server secure after setup
- Weekly: check
sudo lynis audit systemor your update logs, and review recent logins withlast. - Monthly: test a restore from your backup and remove users and SSH keys you no longer need.
- After any change: re-run
sudo ss -tulpnand confirm only the expected ports are open.
Frequently asked questions
Is a firewall enough to secure a Linux server?
No. A firewall only controls which ports are reachable. You still need updates, key-only SSH logins and backups, because attackers use the services you deliberately leave open.Should I change the SSH port?
It reduces log noise from bots but does not stop a targeted attacker. Key-only logins and Fail2Ban or CrowdSec give more protection. See change the SSH port if you still want to.Do I need antivirus on a Linux server?
Most Linux servers do not run a real-time antivirus. A scheduled scan with ClamAV is useful on servers that store user uploads or email. See scan a Linux server for malware.Should I disable SELinux on AlmaLinux or Rocky?
No. Keep it in enforcing mode and fix the label or boolean the error points to. See use SELinux.What should I do if I think my server is already hacked?
Do not keep hardening a server you no longer trust. Follow what to do if your Linux server is hacked.Related guides
VPS and dedicated server guides
Every guide in this section.
First 10 things on a new VPS
Set up a new Linux server step by step.
Set up UFW
Firewall for Ubuntu and Debian.
Set up Fail2Ban
Block SSH brute-force attacks.
Disable root login
Stop direct root logins over SSH.
Server hacked?
Steps to recover safely.
Checked against the official sshd_config manual, Ubuntu Server firewall documentation and Red Hat firewalld documentation on 4 November 2026; the SSH drop-in file (
sshd -t) and lynis audit system were tested on Ubuntu 24.04 LTS. Commands can differ on other distributions or releases.Need Extra Help?
If you encounter any issues, our support team is ready to assist:- Live Chat: Quick assistance via our website.
- Support Ticket: Open a Ticket
- Discord: Join our Community
- Email: support@freakhosting.com
Last Updated: November 2026