Linux hardening for a single server: a practical baseline you can actually maintain
TL;DR. A maintainable baseline beats a one-off “lockdown script” you cannot explain. For a single Linux server you operate — a lab VM or a modest production host — start with updates, a non-root daily user, SSH keys instead of passwords, a host firewall that denies unexpected inbound traffic, unused services turned off, logs you actually read, and backups you have restored once. This is a hardening guide for administrators, not a playbook for attacking a server you do not run.
Scope and honesty
This baseline assumes you have legitimate administrative access, you can take a snapshot or a backup first, and you know what the machine is for. A web server, a jump host and a workstation need slightly different ports. If you do not know why a service is listening, find out before you delete it; if you cannot find out, isolate the host and ask, rather than breaking a production dependency in the name of security.
Do this work in a maintenance window when the host matters to other people. In a lab, take a snapshot and practice the whole list until the machine still does its job afterwards.
A baseline you can finish in an afternoon
1. Record the starting state
Write the distribution and version, the hostname, the role, and the output of a local listener list (ss or the equivalent). Photograph or copy the current firewall rules. If you cannot restore this state, you do not start changing it.
2. Apply updates and set a sensible update habit
Install current security updates. Decide whether unattended upgrades for security patches are appropriate for this host, or whether you will patch on a calendar you actually keep. Neither is “set and forget”: both need a way to notice a failed update.
3. Stop living as root
Create a named sudo user for daily work. Disable direct password login as root over SSH once you have confirmed that your user can still obtain privileges. Shared root passwords in a chat are not a procedure.
4. SSH: keys, no surprise ports as your only defence
Prefer SSH public keys, a current protocol, and a configuration that rejects empty passwords. Moving the port to a non-standard number is not a substitute for keys and a firewall; at best it reduces some of the noise. If you add a second factor for SSH, use a method you can still recover from when a phone is lost. Keep a documented break-glass path that is not a sticky note on the monitor.
5. A host firewall that matches the role
Allow inbound only what the role needs (for example SSH from a management network, and 443 if it is a web server). Default deny the rest. Outbound policy is a later tightening; do not invent a complex egress maze on day one if you will not be able to debug it. Test the allowed paths before you disconnect.
6. Turn off what you do not run
Remove or disable unused packages and services that listen. A forgotten database bound to all interfaces is a more common story than a novel kernel exploit. Every remaining listener should have a name in your notes.
7. Time, logs, and a place they can live
Synchronise time. Keep authentication and sudo logs. Forward logs off the host if you can; an attacker who lands on the only copy of the log can tidy up after themselves. Look at those logs once on a quiet day so that the first time you open them is not during an incident.
8. Backups you have restored
A backup that has never been restored is a rumour. Restore a file, or a whole lab VM, once. Encrypt backups in transit and at rest when they leave the host, and do not store the backup key next to the archive.
9. Automatic leftovers: cron, tokens, and debug flags
Check cron, systemd timers, and application .env files for secrets and for debug modes left on. Rotate any secret that was ever in a ticket or a screenshot. The password article in this series applies to service accounts too.
10. Re-read the listener list
Compare it with step 1. If something new is listening, explain it. If something required has vanished, you are not finished.
Why “more tools” is not a baseline
| Control | Worth adding early? | Condition |
|---|---|---|
| Updates + known user + SSH keys + host firewall | Yes, always | This is the baseline |
| Log forwarding | Yes, as soon as you have somewhere to send them | A second system you also protect |
| Unattended security upgrades | Often yes on a simple host | You must notice failures |
| Mandatory access control (AppArmor/SELinux) | Valuable, not first-hour work | Learn the policy for this role before you enforce it in production |
| External scanners and heavy agents | Later | After the host still does its job and you can explain the agent |
| Exotic kernel tweaks copied from a forum | No, not as a starter set | Change one thing you can measure, not twenty you cannot |
A note on shared and cloud images
If the host was born from a public image, change every default credential, remove vendor SSH keys you do not recognise, and check whether a metadata service or a default user is still reachable in a way you did not intend. Cloud security groups are not a reason to skip the host firewall, and the host firewall is not a reason to leave a security group open to the world.
When you write a short hardening record for the next administrator, keep the actual key material out of the document. SiberAI can help you turn the ten steps above into a team runbook in plain language. Do not paste sshd_config files that contain comments about real jump-host addresses if the note will live in a chat. The security page is relevant whenever a configuration file might contain a secret; the quickstart is enough if you only need a writing workspace.
Key takeaways
- Snapshot or backup first; write the starting listeners down.
- Updates, a named user, SSH keys, a deny-by-default host firewall, and no unused services are the core.
- Logs need a second home, and backups need a test restore.
- Fancy controls come after the host still does its job and you can explain the policy.
- The last step is to compare the listener list with the first step.
Last updated: November 2026.
FAQ
Q: Should I disable SSH password authentication on day one?
A: Yes, once you have confirmed key-based access and a recovery path. Do not disable it in the same change in which you also risk locking yourself out of the console.
Q: Is a web application firewall a substitute for this baseline?
A: No. A WAF does not patch the operating system or remove a forgotten listener.
Q: Can I apply a 200-line “CIS style” script in one go?
A: Prefer a baseline you understand, then add controls from a recognised standard in batches you can test. A script that breaks sudo at 02:00 is not hardening; it is an outage.
Q: Do I need antivirus on a Linux server?
A: It depends on the role and on your organisation’s policy. It does not replace updates, least privilege, and careful listening ports.
Q: How often should I revisit the baseline?
A: After each role change, after a serious patch, and on a calendar you keep — quarterly is a reasonable minimum for a quiet host.
Q: What if I manage many servers?
A: Turn this list into code (configuration management) rather than logging into each one. The principles stay the same: measured changes, recorded state, tested backups.
Q: Is putting the server behind a VPN enough?
A: A management VPN is a good extra layer. It does not excuse default passwords, open package updates, or a database published to every interface on the VPN.
Yorumlar
Yorum Gönder