ShieldHabits
Language: English

Server basics: updates, SSH and firewall

On the internet, attacks start within hours of a flaw becoming public, while people often take weeks to react. Automatic updates and strong SSH access matter far more than tricks such as moving SSH to another port. Several of these changes can lock you out if you do them in the wrong order, so read the warnings.

0 of 6 habits in place

Your progress is saved only in this browser. Nothing is sent to us.

Essential
Do this first. It stops the most common attacks.
Advanced
Extra protection for people facing higher risk.

Keep automatic security updates on

Essential

Leave unattended-upgrades enabled and choose a time for automatic reboots.

Why it matters

Unpatched software is now the most common way into cloud servers. Ubuntu's automatic updates install security fixes every day, but packages from third-party repositories are only included if you add them.

How to do it

  1. Check that unattended-upgrades is installed and enabled.
  2. Set Unattended-Upgrade::Automatic-Reboot-Time to a quiet hour so that kernel fixes take effect.
  3. Add third-party repositories, such as PHP or Node.js sources, to the allowed origins if you want them updated too.
  4. If a surprise service restart would hurt, exclude that service from needrestart.

Use SSH keys and turn off password and root login

Essential

Add an SSH key, test it, then switch off password and root logins.

Why it matters

Password logins invite endless guessing attacks, and root login hands an attacker everything at once. Keys are far stronger, but careless SSH changes are the most common way people lock themselves out of their own servers.

How to do it

  1. Add your public key, then confirm in a new terminal that you can log in with it, keeping the old session open.
  2. Put your settings in a file under /etc/ssh/sshd_config.d/, because files there override the main configuration.
  3. Set PasswordAuthentication no and PermitRootLogin no.
  4. Run sudo sshd -t to check the configuration before you restart SSH.

Watch out: Keep your current session open until a fresh login with your key works. If the test fails, you can still undo the change.

Enable the firewall in the right order

Essential

Allow SSH before you turn on ufw, and limit SSH to your own IP address if you can.

Why it matters

Ubuntu's ufw firewall is off by default. Turning it on before allowing SSH cuts off your own connection.

How to do it

  1. Run sudo ufw allow OpenSSH (or allow your SSH port) first.
  2. Allow only the other ports you need, such as 80 and 443 for a website.
  3. Then run sudo ufw enable and check the result with sudo ufw status.
  4. Where possible, allow SSH only from your own IP address.

Watch out: Never run sudo ufw enable on a remote server before the SSH rule is in place.

Run a security audit every quarter

Advanced

Use a tool such as Lynis to check the server's configuration, and work through its suggestions.

Why it matters

Audits catch settings that drift over time. Lynis runs on the server itself, so it is less disruptive than network scanners.

How to do it

  1. Install Lynis from your distribution's packages or the official site.
  2. Run sudo lynis audit system.
  3. Work through the warnings first, then the suggestions.
  4. Repeat every quarter and compare the results.

Last reviewed November 28, 2026