Linux Server Security: A Step-by-Step Checklist
A Linux server security checklist: automatic updates, SSH keys, a firewall, Fail2ban, unneeded services, isolation, backups and security audits.

Contents
Linux server security isn't a single setting; it's a set of simple measures that complement each other. Every internet-facing server faces automated scans and password-guessing attacks within minutes of being set up. The good news: almost all of these attacks are neutralized by a few basic steps in this checklist.
In this guide, you'll find how to secure a new Linux server step by step, why each step matters, and our related guides for detailed walkthroughs, all in one place.
The checklist
| Step | Why? |
|---|---|
| Update the system | Closes known vulnerabilities |
| Turn on automatic security updates | Vulnerabilities get patched even when you're busy |
| Create a regular user | Avoids working as root all the time |
| Switch to SSH key login | Neutralizes password-guessing attacks |
| Turn on the firewall | Exposes only the ports you need |
| Install Fail2ban | Blocks persistent attackers automatically |
| Turn off unneeded services | Shrinks the attack surface |
| Run applications as separate users | Stops one vulnerability from affecting the whole server |
| Protect secrets | Prevents passwords and keys from leaking |
| Take backups and test restoring them | Lets you recover when everything goes wrong |
| Monitor logs and resources | Helps you spot problems early |
1. Keep the system up to date
When you first connect to the server, update all packages:
sudo apt update && sudo apt upgrade
Then make sure security updates are installed automatically:
sudo apt install unattended-upgrades
sudo dpkg-reconfigure --priority=low unattended-upgrades
By default, unattended-upgrades only installs security updates. Kernel updates don't take effect until the server is restarted; if the /var/run/reboot-required file exists, restart at a convenient time. On AlmaLinux and Rocky Linux, the dnf-automatic package does the same job.
2. A regular user and an SSH key
Instead of working as root all the time, create a user with sudo rights, set up SSH key login, and then turn off password login and root login:
PasswordAuthentication no
PermitRootLogin no
Before making these changes in the /etc/ssh/sshd_config file, always test in a separate terminal that you can connect with the new user and your key. We cover all the steps in detail in our What is SSH? article.
3. Firewall
Block everything incoming by default and open only the ports you actually use:
sudo ufw default deny incoming
sudo ufw default allow outgoing
sudo ufw allow OpenSSH
sudo ufw allow 443/tcp
sudo ufw enable
Don't forget to add the OpenSSH rule before the enable command; otherwise you'll lock yourself out. Never expose services such as databases and admin panels to the internet; use an SSH tunnel or WireGuard for remote access. If you use Docker, remember that published ports bypass ufw rules; the details are in our What is a port? and How to install Docker articles.
4. Fail2ban
Fail2ban automatically blocks IP addresses that make repeated failed login attempts for a while. SSH key login already provides the main protection, but Fail2ban reduces the noise in the logs and also protects other services such as Nginx. We cover the setup in our How to install Fail2ban guide.
5. Turn off unneeded services
Every service on the server that listens to the outside is a door. See what's listening:
sudo ss -tulpn
If you see a service you don't recognize or don't use, stop it and keep it from starting at boot:
sudo systemctl disable --now service-name
Removing packages you don't use also shrinks the attack surface.
6. Run applications as separate users
Run web applications, bots and game servers as a separate user for each one instead of root. This way, a vulnerability in one application can only reach that user's files. Be careful with file permissions too: settings that give everyone write access, like chmod 777, may look like they solve problems, but they're a serious security hole. We cover permissions in our Basic Linux commands guide.
7. Protect secrets
- Write passwords, API keys and database credentials in files like
.envinstead of in the code, and don't add these files to the Git repository. - Make sure secret files can only be read by the user they belong to (
chmod 600). - Use a separate password and key for each service and person; when something leaks, you only need to change that one.
We cover managing secrets during deployment in our How to deploy with Git guide.
8. Backups
Security measures may not be enough one day; on that day, a backup is what saves you. Take backups following the 3-2-1 rule, keep at least one copy encrypted and somewhere independent of the server, and test restoring regularly. The details are in our Server backups guide.
9. Monitoring and auditing
- Login records:
lastshows recent logins, andsudo journalctl -u sshshows the SSH logs. If you see a successful login from an IP address you don't recognize, act immediately. - Resource usage: A process you don't recognize that constantly uses CPU can be a sign of a compromised server. We explain how to check this in our Why is my server slow? article.
- Security audit: The open-source Lynis tool scans your server against hundreds of checkpoints and makes recommendations:
sudo apt install lynis sudo lynis audit system - Availability: Track whether your server is up with a monitoring service; take a look at our What is uptime? article.
10. Protect your account too
The account you manage your server with matters as much as the server itself. Turn on two-factor authentication in your provider's client area and use a unique password for each service. Someone with access to the panel can reinstall your server, reach your backups or reset passwords.
Security at Nodesty
With full root access on Nodesty AMD Ryzen 9 9950X VPS and AMD EPYC 7763 VPS plans, you can apply every step in this checklist. L3–L7 nShield DDoS protection filters network-level attacks before they reach your server, free daily backups kept for 7 days form your last safety net, and when your SSH access is cut off, you can always reach your server through the web console. You can also protect your account by turning on two-factor authentication in your client area.
Frequently Asked Questions
What should I do first on a new server?
Update the system, create a regular user with sudo rights, turn on SSH key login and turn off password login, and enable the firewall so that it allows only the ports you need. These four steps neutralize the vast majority of automated attacks on an internet-facing server from day one.
Should I install antivirus on my server?
On Linux servers, up-to-date software, strong authentication and closed ports matter far more than classic antivirus programs. On servers where users upload files, a scanner like ClamAV can be used as an extra layer. On shared web hosting, the provider takes care of this kind of protection.
How can I tell if my server has been compromised?
The most common signs are processes you don't recognize that constantly use a lot of CPU, users or SSH keys you don't know about, unexpected outbound traffic and abuse reports from your provider. In that situation, rebuilding the server from a clean backup is safer than trying to clean it up.
Can automatic updates break the server?
By default, unattended-upgrades only installs security updates, and these updates are prepared to be compatible with the existing versions. The chance of them causing problems is low, and leaving a known vulnerability unpatched is a much bigger risk. Always do major version upgrades by hand, after taking a backup.
Why is logging in as root dangerous?
root is the account that can do anything on the server, and because its user name is known to everyone, it's the first target of automated attacks. Logging in as a regular user and using sudo only when needed both shrinks the attack surface and limits the damage from accidental mistakes.
How do I protect my Nodesty account?
The account you manage your server with matters as much as the server itself. Turn on two-factor authentication in the Nodesty client area, use a strong and unique password, and regularly check the sessions and access changes on your account.
About the author
Nodesty Team · Infrastructure & Support
The Nodesty team runs our servers, network and DDoS protection day to day and answers customer support requests around the clock. These guides come from that work.
Related articles

Website Hacked? What to Do, Step by Step
Website hacked? What to do: the signs, first response, passwords, finding malicious files, restoring a clean backup, WordPress cleanup and prevention.

How to Set Up WireGuard: Run Your Own VPN Server
How to set up WireGuard as your own VPN on an Ubuntu server: generating keys, wg0.conf, IP forwarding and NAT, client settings and QR codes for phones.

How to Install Fail2ban: Protect Your Server From Attacks
How to install Fail2ban: block SSH brute-force attacks, configure jail.local, protect Nginx, manage banned IP addresses and use Fail2ban with ufw.