A fresh Linux install is not insecure, but it is unfinished. Canonical's own Ubuntu Server security guidance says a fresh install is relatively safe for immediate use — and then lists the work that actually keeps it safe. The CIS Benchmarks for Ubuntu Linux and Debian make the same point as a checklist: hundreds of individual settings, organised so an administrator can audit them one by one. You do not need all of them on day one. You need five steps, in this order, done properly: patch automatically, lock down accounts, harden SSH, close the network with a firewall, and then verify and watch the system. This article walks through each step with the commands and settings the official documentation itself gives. Educational and defensive throughout — secure systems you own or administer.
Why five steps, and why this order
Most compromised Linux machines were not defeated by an exotic exploit. They were left unpatched, they allowed password sign-in to an account an attacker could guess, or they ran a service nobody remembered installing. The five steps below attack exactly that pattern. Patching comes first because an unpatched known vulnerability defeats every later control. Accounts and SSH come next because they are the front door. The firewall limits what can even reach that door. Verification comes last because a hardening step you never checked is a hope, not a control — the CIS Benchmarks exist precisely so you can audit the result instead of trusting it.
Step 1: Patch automatically — do not rely on remembering
Canonical's guidance is blunt: regularly update the system to stay protected from known vulnerabilities, and use the unattended-upgrades package to fetch and install security updates automatically. On Ubuntu and Debian that is:
sudo apt update && sudo apt upgrade sudo apt install unattended-upgrades sudo dpkg-reconfigure --priority=low unattended-upgrades
By default unattended-upgrades runs daily. Two honest limits belong here. First, automatic patching covers the packages your distribution maintains — software you installed by hand from outside the repositories is your own responsibility to track. Second, stay on a supported release: when a release reaches end of life, security updates stop, and no hardening step compensates for that. Canonical notes that Ubuntu Pro extends security maintenance, including Expanded Security Maintenance and Livepatch kernel fixes applied without a reboot, which matters most on machines that cannot afford downtime. Whatever you choose, the rule is the same: patching is a system, not an occasional chore.
Step 2: Lock down accounts and sudo — least privilege, enforced
Every account is a door, so start by knowing how many doors you have. Review the accounts that can sign in, remove or lock the ones nobody uses, and make sure no service is running under a shared human password. The principle, named directly in Canonical's access-control guidance, is least privilege: each person and each service gets only the access its work requires, and nothing more.
On a personal or small-team machine that means three concrete habits. Use a named personal account for administration instead of working as root all day; root's power should be borrowed through sudo for one command at a time, not lived in. Protect that sudo access with a strong, unique password — NIST SP 800-63B's guidance favours long passphrases over short, complicated strings that people write down. And audit sudo membership: everyone in the sudo group can become root, so that group's membership list is a security document. Check it, and remove anyone who no longer needs it.
Step 3: Harden SSH — keys only, no root, and a guard at the door
If the machine accepts remote sign-in, SSH is the service attackers will test first, because it is common, it is powerful, and password guessing against it is automated worldwide. The CIS Benchmarks and distribution hardening guides agree on the core settings in /etc/ssh/sshd_config:
PermitRootLogin no PasswordAuthentication no PubkeyAuthentication yes
Keys only means an attacker needs your private key file, not a guessable password — generate it with ssh-keygen, protect it with a passphrase, copy the public half with ssh-copy-id, and only then turn password authentication off, after you have confirmed key sign-in works in a second session so you do not lock yourself out. Disabling direct root sign-in forces an attacker to compromise a named account and then still get past sudo. Restart the service with sudo systemctl restart ssh after any change, and keep the current session open until the new settings are proven.
Add a guard as well: Fail2ban, documented by its own project, watches the authentication logs and temporarily bans addresses that fail repeatedly. It does not replace keys — it cuts the noise and slows the guessing to a crawl. Change nothing else exotic here: the standard settings, correctly applied, are what the benchmarks ask for.
Step 4: Firewall everything you do not use — default deny
A firewall is where you state, in enforceable form, which services this machine offers the network. Canonical's guidance recommends a firewall on Ubuntu systems and points to ufw, the Uncomplicated Firewall, as the front end:
sudo ufw default deny incoming sudo ufw default allow outgoing sudo ufw allow OpenSSH sudo ufw enable sudo ufw status verbose
Allow each additional service deliberately, one rule at a time, and only if something real needs it. Then shrink what is listening in the first place: remove packages you do not need — Canonical makes the same point, because every installed service is attack surface — and list what is actually listening with ss -tulpn. If a port is open and nobody can say why, that is a finding: close it, disable the service with systemctl, and note the change. A desktop that never serves files does not need a file server running, and a laptop does not need its SSH port open to the whole internet just because SSH is installed.
Step 5: Verify, log, and back up — prove it, then keep proving it
Hardening without verification drifts. The CIS Benchmarks are published as audit-ready recommendations for exactly this reason, and tooling exists to check a system against them — Canonical ships CIS audit tooling for Ubuntu, and the open-source Lynis auditor performs a broad local security audit and reports hardening suggestions with references. Run an audit after your first pass, fix what it finds in priority order, and re-run it after major changes.
Watching the system is the other half. The systemd journal (journalctl) and the authentication log record who signed in, who used sudo, and what failed — review them, especially after any alert from Fail2ban. Finally, back up: a secured machine that cannot be restored is still a loss waiting for a disk failure instead of an attacker. Keep at least one backup that is not permanently attached to the machine, and test restoring a file from it. Security that has never survived a restore test is unfinished in the same way an untested SSH change is.
The five steps as a one-page checklist
One: turn on automatic security updates and confirm you are on a supported release. Two: remove unused accounts, enforce least privilege, and audit sudo membership. Three: SSH with keys only, no root sign-in, no passwords, Fail2ban watching the log. Four: firewall on, default deny incoming, only deliberate services allowed, unused packages removed. Five: audit against the CIS Benchmark or with Lynis, read the logs, and keep a tested backup. Worked in order, on a machine you own, those five steps move a Linux system from default to defended — not invulnerable, because no honest guide promises that, but no longer the easy target automated attacks are built to find.
By Karl Amber
Sources
– Canonical — Ubuntu Server documentation, "Security suggestions": keep the system up to date, unattended-upgrades for automatic security updates, remove unneeded packages, least privilege, and use a firewall (ufw).
– Center for Internet Security (CIS) — CIS Benchmarks for Ubuntu Linux and Debian Linux: auditable secure-configuration recommendations, Level 1 and Level 2 profiles.
– NIST SP 800-63B — Digital Identity Guidelines: authentication and lifecycle management, including long passphrases and memorised secrets.
– OpenSSH — sshd_config manual page: PermitRootLogin, PasswordAuthentication, and PubkeyAuthentication settings.
– Fail2ban project documentation — log-based intrusion prevention that bans repeatedly failing addresses.
– Lynis (CISOfy) project documentation — open-source security auditing for Linux systems.
Editor's note: this article is part of ScanderLoud's Cybersecurity & Networking series. It was researched from primary and authoritative sources — Canonical's Ubuntu Server security documentation, the CIS Benchmarks, NIST SP 800-63B, the OpenSSH manual, and the Fail2ban and Lynis project documentation — and is original, educational, and defensive throughout. No NetworkChuck video was opened or used.
Leave a Reply