D Darkless Help
Open the portal

Help Running your server First steps

Secure a new server

The first half hour on a new server: updates, your own user, key-only SSH, a firewall, fail2ban and automatic security updates.

5 min Updated 7 Nov 2026 Ubuntu, Debian, AlmaLinux

A new server gets its first login attempts from strangers within minutes. Half an hour, once, covers most of what goes wrong. Work through it in order, with an SSH key on your computer first: see Make an SSH key and use it.

The two families name a few things differently:

WhatUbuntu / DebianAlmaLinux / Rocky
Packagesaptdnf
Group allowed to use sudosudowheel
SSH servicesshsshd
Firewall on the serverufwfirewalld
fail2ban comes fromThe main repositoryEPEL
Automatic updatesunattended-upgradesdnf-automatic

1. Install updates#

A fresh image can be weeks old. Bring it up to date before anything else:

Ubuntu / Debian

apt update && apt upgrade -y

AlmaLinux / Rocky

dnf upgrade -y

If a new kernel came in, reboot now, and log in again when it's back:

reboot

2. Make your own user#

As root, one typo can do anything. Make an everyday user who uses sudo when it needs root. The examples use alex.

Ubuntu / Debian

adduser alex

Give it a password (sudo asks for it) and leave the other details empty. Then let it use sudo:

usermod -aG sudo alex

On a minimal Debian, sudo may not be installed: apt install -y sudo.

AlmaLinux / Rocky

useradd -m -G wheel alex

Members of wheel may use sudo. Set the password sudo will ask for:

passwd alex

Copy root's SSH keys to the new user, so the same key lets you in:

install -d -m 700 -o alex -g alex /home/alex/.ssh
install -m 600 -o alex -g alex /root/.ssh/authorized_keys /home/alex/.ssh/authorized_keys

Keeping this window open, log in as the new user from a second terminal:

ssh [email protected]

Check sudo works. It asks for alex's password and should answer root:

sudo whoami

3. Allow SSH keys only#

Turn off password logins, and let root in with a key only. Bots guessing passwords then get nowhere.

Put the settings in their own file. The first value SSH finds wins, so a name starting 00- beats anything the image put there:

sudo tee /etc/ssh/sshd_config.d/00-key-only.conf <<'EOF'
PasswordAuthentication no
KbdInteractiveAuthentication no
PermitRootLogin prohibit-password
EOF

Check the settings make sense, then see what SSH will actually use:

sudo sshd -t
sudo sshd -T | grep -Ei '^(passwordauthentication|kbdinteractiveauthentication|permitrootlogin)'

The first two should say no and the last without-password (SSH's name for prohibit-password). Then restart SSH. Open sessions stay open.

Ubuntu / Debian

sudo systemctl restart ssh

AlmaLinux / Rocky

sudo systemctl restart sshd

From a third terminal, check you can still get in with your key:

ssh [email protected]

Only when that works, close the old sessions.

4. Turn on a firewall#

Allow SSH before you turn it on.

Ubuntu / Debian

Ubuntu has ufw already. On Debian, install it first: sudo apt install -y ufw.

sudo ufw allow 22/tcp
sudo ufw enable

Check what it allows:

sudo ufw status verbose

To allow a website later: sudo ufw allow 80/tcp and sudo ufw allow 443/tcp.

AlmaLinux / Rocky

AlmaLinux uses firewalld. Install and start it if it isn't running. It allows SSH from the start:

sudo dnf install -y firewalld && sudo systemctl enable --now firewalld

Check what it allows:

sudo firewall-cmd --list-all

To allow a website later:

sudo firewall-cmd --permanent --add-service=http --add-service=https && sudo firewall-cmd --reload

Two firewalls, one path

A VPS also has a firewall in the portal, outside the server, on the Networking tab: see Set up the firewall. Traffic passes it first, then the server's own, so a port has to be open in both.

5. Ban repeat offenders with fail2ban#

Bots keep knocking even with passwords off. fail2ban blocks an address for a while after repeated failed logins.

Ubuntu / Debian

sudo apt install -y fail2ban

AlmaLinux / Rocky

sudo dnf install -y epel-release && sudo dnf install -y fail2ban

Tell it to watch SSH, reading the system journal:

sudo tee /etc/fail2ban/jail.local <<'EOF'
[sshd]
enabled = true
backend = systemd
maxretry = 5
findtime = 10m
bantime = 1h
EOF

Start it, and have it start at every boot:

sudo systemctl enable --now fail2ban && sudo systemctl restart fail2ban

See who's banned:

sudo fail2ban-client status sshd

If you ever ban yourself, wait an hour or unban your address from the console: sudo fail2ban-client set sshd unbanip 198.51.100.7.

6. Install security updates automatically#

Let the server install security fixes by itself:

Ubuntu / Debian

Ubuntu does this already. On Debian, install it and switch it on:

sudo apt install -y unattended-upgrades
sudo tee /etc/apt/apt.conf.d/20auto-upgrades <<'EOF'
APT::Periodic::Update-Package-Lists "1";
APT::Periodic::Unattended-Upgrade "1";
EOF

AlmaLinux / Rocky

sudo dnf install -y dnf-automatic
sudo systemctl enable --now dnf-automatic-install.timer

Kernel updates still need a reboot to take effect. See Keep your server updated for checking that, and for automatic reboots.

What's next#

Still stuck? Open a ticket and say which guide you followed.