The first hour on a fresh Ubuntu server: a security checklist

A new server starts getting SSH login attempts within minutes of going online. The practical steps we take in the first hour (updates, SSH, firewall, fail2ban, backups) with the commands to run.

AskMyServers team · · 3 min read

Put a new server on the internet and check the SSH log an hour later. You'll almost certainly find login attempts from addresses you've never heard of, trying root, admin, ubuntu and a list of common passwords. Nobody is targeting you personally. Bots scan every address, all the time.

That's why the first hour matters. Here's the checklist we work through on a fresh Ubuntu server, roughly in this order.

1. Update everything

sudo apt update && sudo apt upgrade -y

Then turn on automatic security updates so you don't have to remember:

sudo apt install -y unattended-upgrades
sudo dpkg-reconfigure -plow unattended-upgrades

On a production server you may prefer to leave automatic reboots off and restart in a quiet hour yourself.

2. Make SSH harder to brute force

The strongest option is to log in with SSH keys and switch off password login completely. If you do keep passwords, use a long random one, and tighten a few settings in a file like /etc/ssh/sshd_config.d/00-hardening.conf:

MaxAuthTries 3
LoginGraceTime 30
X11Forwarding no
AllowAgentForwarding no

Always test the config and keep your current session open while you check that a new login still works:

sudo sshd -t && sudo systemctl reload ssh

3. Turn on the firewall

Allow only what you need. For a typical web server that's SSH and web traffic:

sudo ufw allow OpenSSH
sudo ufw allow 'Nginx Full'
sudo ufw enable
sudo ufw status verbose

Databases like PostgreSQL and Redis should listen on 127.0.0.1 only, unless another server genuinely needs to reach them.

4. Ban repeat offenders with fail2ban

fail2ban watches the logs and blocks addresses that keep failing to log in:

sudo apt install -y fail2ban

A small /etc/fail2ban/jail.local goes a long way:

[DEFAULT]
ignoreip = 127.0.0.1/8 ::1 YOUR.OFFICE.IP
bantime = 1d
findtime = 10m
maxretry = 3
bantime.increment = true

[sshd]
enabled = true

Putting your own IP in ignoreip saves you from locking yourself out with a typo. With bantime.increment, repeat visitors get longer bans each time.

5. Web server basics

  • Redirect HTTP to HTTPS and get a certificate (certbot --nginx makes this easy).
  • Turn off old TLS versions; TLS 1.2 and 1.3 are enough.
  • Hide the version number (server_tokens off; in NGINX).
  • Add security headers such as Strict-Transport-Security and X-Content-Type-Options.
  • Return nothing for paths bots love to probe, like /.env, /.git and /wp-login.php, if you don't use them.

6. Backups, before you need them

Set up an automatic, daily database backup and keep a couple of weeks of copies. Then actually try restoring one; a backup you've never restored is a hope, not a plan. Keep at least one copy off the server, because a backup on the same disk won't help if the server itself is lost.

7. Know when someone logs in

A simple email on every SSH login from an unfamiliar address is one of the cheapest early warnings there is. If you ever get one you don't recognise, you'll know within seconds instead of finding out weeks later.

The checklist

StepDone when
UpdatesFully patched, automatic security updates on
SSHKeys (or a strong password) and tightened settings
FirewallOnly the ports you need are open
fail2banFailed logins lead to bans
WebHTTPS only, modern TLS, headers set
BackupsDaily, retained, restore tested, one copy off-server
AlertsYou hear about logins and outages

None of this takes long, and it removes most of the easy ways in. Once it's done, monitoring tells you when something drifts, such as a disk filling up, a certificate nearing expiry, or a service going down, so the server stays in the state you left it.

Monitor your server for free

The first hour on a fresh Ubuntu server: a security checklist · AskMyServers