Skip to content
zefıly
← All posts

The first 10 security steps on a new Ubuntu server

4 min read

A fresh Ubuntu 26.04 server accepts password logins and has no firewall rules. Ten steps for the first hour, in order, with the defaults we found on a new system and the commands to change them.

A new server is found by scanners within minutes of getting its IP address. Most of them try one thing: logging in over SSH with common passwords. The steps below close that door first and then work outwards.

We read the defaults on a fresh Ubuntu 26.04.1 system on 12 November 2026 (OpenSSH 10.2).

In short

  • Ubuntu 26.04's SSH defaults: PasswordAuthentication yes, PermitRootLogin prohibit-password, MaxAuthTries 6.
  • Log in with a key, then turn password logins off.
  • Open only the ports you use: 22, 80, 443.
  • Let security updates install themselves.
  • Give every site its own Linux user. Take backups before you need them.

1. Update the system

sudo apt update && sudo apt full-upgrade

The image your provider installed may be weeks old. Reboot if a new kernel came in.

2. Create your own user

Do not work as root.

sudo adduser deploy
sudo usermod -aG sudo deploy

3. Log in with an SSH key

On your own computer:

ssh-keygen -t ed25519
ssh-copy-id deploy@your-server

Open a second terminal and check that ssh deploy@your-server works without a password before you go on. Keep the first session open until then.

4. Turn off password logins

This is what we found on the fresh system:

sudo sshd -T | grep -E 'passwordauthentication|permitrootlogin|maxauthtries|x11forwarding'
maxauthtries 6
permitrootlogin prohibit-password
passwordauthentication yes
x11forwarding yes

Root cannot log in with a password, but every other user can. Create /etc/ssh/sshd_config.d/10-hardening.conf:

PasswordAuthentication no
PermitRootLogin no
X11Forwarding no
MaxAuthTries 3
sudo sshd -t && sudo systemctl reload ssh

Run sshd -T again to see that the values changed. Some providers' images add their own file to sshd_config.d; the first file that sets a value wins, so check the result, not only your file.

5. Turn the firewall on

sudo ufw default deny incoming
sudo ufw default allow outgoing
sudo ufw allow 22/tcp
sudo ufw allow 80/tcp
sudo ufw allow 443/tcp
sudo ufw enable

Allow SSH before ufw enable, or you lock yourself out. If your provider has a firewall in front of the server, use that as well, and open port 22 only for your own IP addresses there.

6. Automatic security updates

sudo apt install unattended-upgrades

On Ubuntu 26.04 this is enough: the package turns the daily run on (APT::Periodic::Unattended-Upgrade "1") and installs from the security pocket. Kernel updates still need a reboot; plan one regularly, or allow automatic reboots at night in /etc/apt/apt.conf.d/50unattended-upgrades.

7. Slow down the guessers

sudo apt install fail2ban

Ubuntu 26.04 ships fail2ban 1.1.0 with the SSH jail already on: five failed attempts within ten minutes ban the address for ten minutes. With password logins off this is mostly log hygiene, but it also protects other services you add later. CrowdSec is an alternative that shares block lists between servers.

8. See what is listening

sudo ss -tulpn

Every line is a door. A database that listens on 0.0.0.0 instead of 127.0.0.1 is reachable from the internet unless the firewall stops it. More in How to check open ports on a Linux server.

9. One user per site

If all sites run as www-data, a hole in one of them reaches the files of all the others. Give each site its own Linux user and its own PHP pool. See Running several PHP versions side by side for a pool file.

10. Backups, outside the server

A backup on the same disk is lost with the disk. Copy to storage at another provider, on a schedule, and restore one once to see that it works. See A backup you have not restored is not a backup.

What this does not cover

These steps protect the server. They do not fix a vulnerable application. Keep WordPress, plugins and your own dependencies updated, and consider a web application firewall for sites you cannot update quickly.

With Zefily

When you connect a server to Zefily, much of this list is applied for you: the firewall, CrowdSec, a security baseline for the server, and every site as its own Linux user. The Security center shows a score per server and what is still open, and checks the open ports for you. See Security center and Firewall and users.

Frequently asked questions

Does Ubuntu 26.04 allow SSH password logins by default?

Yes. On a fresh Ubuntu 26.04 system sshd reports passwordauthentication yes. Root is limited to keys (permitrootlogin prohibit-password).

How do I disable SSH password authentication on Ubuntu?

Put PasswordAuthentication no in a file under /etc/ssh/sshd_config.d/, run sshd -t, reload ssh, and confirm with sshd -T. Test key login in a second session first.

Which ports should be open on a web server?

22 for SSH, 80 and 443 for the web. Everything else, such as databases, should listen on 127.0.0.1 or be closed by the firewall.

Are automatic updates safe on a server?

Security updates from Ubuntu's security pocket are meant to be installed automatically and rarely break things. Not installing them is the larger risk.

Is fail2ban still needed with key-only SSH?

It is less important, since passwords cannot be guessed, but it keeps logs quieter and protects other services. Ubuntu 26.04 enables its SSH jail by default.

See Security updates and notices for how Zefily tells you about updates.

More posts

Black Friday & Cyber Monday

Before you go: lifetime plans are on sale

Pay once for a lifetime plan, or get 30% off the first year of any yearly plan.

Only 100 lifetime plans per plan. When they are gone, they are gone.

See the campaign

Amazing November

See the campaign →