Skip to content
Pipoline
sk

Securing a Linux Server: 10 Steps No Server Should Be Missing

A server connected to the internet faces automated attacks within minutes of starting. Here is a practical checklist – from SSH keys and updates to firewalls, monitoring and auditing – that removes most common risks.

Pipoline Team4 min read

Start a new server with a public IP address and look at the logs. Within minutes you will see the first SSH login attempts with names like root, admin or test. It isn’t a targeted attack – automated bots scan the internet constantly and try everything they find.

The good news: a few basic measures stop most common attacks. This is the list we use as a starting point for every server we take over.

1. Log in with SSH keys only

Passwords can be guessed; keys practically can’t. Log in to the server only with SSH keys, switch off password authentication and forbid logging in directly as root. On Ubuntu and Debian a separate configuration file is all you need:

# /etc/ssh/sshd_config.d/10-hardening.conf
PasswordAuthentication no
KbdInteractiveAuthentication no
PermitRootLogin no
MaxAuthTries 3
AllowGroups ssh-users

Before restarting, check the configuration with sudo sshd -t, and keep your current session open until you have confirmed in a new window that you can still log in. Otherwise it’s easy to lock yourself out.

2. Regular security updates

Most successful attacks exploit known flaws that already have a fix. Set security updates to install automatically – with unattended-upgrades on Debian and Ubuntu, or dnf-automatic on RHEL and its derivatives. Plan larger updates and reboots for a maintenance window.

Watch the version of the distribution itself, too: a system that has reached end of life no longer receives security fixes.

3. Firewall: allow only what is needed

Deny everything by default and open only the ports the service really needs – typically 80 and 443 for the web, and SSH only from specific addresses or through a VPN. On the server, ufw or nftables will do; in the cloud, add security groups on top. Databases, Redis and admin interfaces should never be reachable from the internet.

4. Protection against credential guessing

A tool such as fail2ban watches the logs and temporarily blocks addresses that repeatedly fail to log in – on SSH, but also on web forms or a mail server. With key-only logins it is more of a complement that keeps the logs cleaner.

5. Least privilege

Every administrator has their own account with rights through sudo, not a shared account with a common password. Applications run under their own users without admin rights. When someone leaves the company or project, their access is removed the same day.

6. Only the services you need

What isn’t running on the server can’t be attacked. Check which services are listening on the network with ss -tulpn, and switch off or uninstall anything you don’t need.

7. Encryption everywhere

Web services over HTTPS only, with automatically renewed certificates (for example from Let’s Encrypt). Encrypted connections between the application and the database too, if they aren’t on the same machine. Encrypted disks and backups – in the cloud this is usually a single setting.

8. Secrets outside the code

Database passwords, API keys and tokens don’t belong in the repository, in world-readable configuration files or in your shell history. Store them in a secrets manager (such as AWS Secrets Manager or HashiCorp Vault), or at least in files with restricted permissions.

9. Logs and monitoring

Without logs you can’t find out what happened, and without monitoring you won’t even know that something did. Ship logs off the server – otherwise an attacker who takes over the server can delete them. Set up alerts for unusual events: logins from new locations, sudden spikes in load, a full disk or newly opened ports.

10. Backups and regular audits

Even a well-secured server isn’t invulnerable, so you need backups you can actually restore from. And security isn’t a one-off task: tools such as Lynis or the CIS Benchmarks recommendations help you check regularly that your setup hasn’t drifted over time.

Keeping it up across many servers

With one server you can set everything up by hand. With five, you can’t – and with manual setup something always gets forgotten. That’s why we write security settings as code (for example in Ansible or SaltStack), and new servers are built automatically from the same recipe. Every server is then secured the same way, and changes can be reviewed.

For fleets managed with SaltStack we built an open-source web UI, Salt Shaker. It shows in one place which servers have drifted from their configuration, where security updates are pending and which packages have known vulnerabilities (CVEs). It can score servers against CIS-style recommendations, and it records every change in an audit log. So instead of checking most of the steps on this list by hand every now and then, you see their status continuously across the whole fleet. You can try it without a Salt master of your own in demo mode with simulated servers – see the documentation for how.

🔐 Want to know how your servers measure up?

As part of our Linux server administration we carry out a security audit, fix the problems we find and set up updates, monitoring and backups so that they work for the long term. Get in touch – the first consultation is free and comes with no obligation.

You might also like

Linux4 min read

Server Backups: A Backup You Have Never Restored Is Not a Backup

Most companies back up their servers. Far fewer know whether those backups can actually be restored, or how long it would take. The 3-2-1 rule, ransomware protection, RPO and RTO, and regular restore tests – practical and to the point.

Web4 min read

A Slow Website Costs You Customers: How to Speed It Up and What Core Web Vitals Are

Website speed affects whether visitors stay, whether they fill in your form and how Google shows you. Here is what Core Web Vitals measure, how to find out where the problem is, and which fixes help the most.

Cloud3 min read

Does Your Company Need Kubernetes? The Honest Answer Is Often No

Kubernetes is a powerful tool, but also a source of unnecessary complexity and cost. Here is when it really pays off, what the simpler alternatives are, and how to decide based on your situation rather than on trends.

Contact

Need a hand with this?

Tell us in a few sentences what you need. We will get back to you shortly and suggest the next steps – no strings attached.

Prefer a detailed questionnaire? Request a quote

By submitting the form you agree to the processing of personal data.