Loading…
Loading documentation...
Give a new Ubuntu 24.04 server your own sudo user, sign-in by SSH key only, a firewall and automatic security updates.
Commands checked on 2026-10-27 with Ubuntu 24.04, OpenSSH 9.6, ufw 0.36.
A server you sign in to as your own user, with your SSH key and never a password, where that user can run commands as root with sudo. The firewall admits SSH and nothing else until you open a port on purpose, and security updates install themselves every day.
sudo. On a Servers Are Up Linux server that account is sauuser: its password is on the server's page, and root cannot sign in at all. See SSH Key Management for how to reach the server over SSH.ssh-keygen -t ed25519 makes one; the public half is the one-line file ending in .pub.In the commands, SERVER_ADDRESS and PORT are the address and port you sign in with, deploy is the user you create (use any name), and YOUR_PUBLIC_KEY is the whole line of your .pub file.
Install the updates the image was built without, before anything else runs on the server.
sudo apt update
sudo DEBIAN_FRONTEND=noninteractive apt -y full-upgrade
When apt finishes, look for the file /var/run/reboot-required. If it exists, a new kernel or library is waiting: run sudo reboot, wait a minute and sign in again.
A user of your own, with its own password, means every command you run as root is logged under your name. adduser asks for the new password twice. sudo will ask for this password, so keep it.
sudo adduser --comment "" deploy
sudo usermod -aG sudo deploy
adduser prints passwd: password updated successfully after the second password. Check the groups with id deploy: the list includes 27(sudo).
The key goes in the user's authorized_keys file, and SSH ignores that file unless only the user can write to it.
sudo install -d -m 700 -o deploy -g deploy /home/deploy/.ssh
echo 'YOUR_PUBLIC_KEY' | sudo tee /home/deploy/.ssh/authorized_keys > /dev/null
sudo chown deploy:deploy /home/deploy/.ssh/authorized_keys
sudo chmod 600 /home/deploy/.ssh/authorized_keys
Do this before turning passwords off. Run it on your own computer, not on the server.
ssh -t -p PORT deploy@SERVER_ADDRESS 'sudo -v && echo sudo works'
SSH signs you in with the key without asking for a password. sudo then asks for the password from step 2, and the last line reads sudo works. If SSH asks for a password instead, stop here and read What can go wrong.
A file in /etc/ssh/sshd_config.d/ whose name sorts first wins over the others, so 00- is read before the 50-cloud-init.conf that cloud images ship with password sign-in on.
printf 'PasswordAuthentication no\nKbdInteractiveAuthentication no\nPermitRootLogin no\n' | sudo tee /etc/ssh/sshd_config.d/00-hardening.conf > /dev/null
sudo sshd -t
sudo systemctl reload ssh
sudo sshd -T | grep -E '^(passwordauthentication|kbdinteractiveauthentication|permitrootlogin) '
sshd -t prints nothing when the configuration is valid. The last command prints the three settings the server now uses:
permitrootlogin no
passwordauthentication no
kbdinteractiveauthentication no
On a Servers Are Up server, the web terminal on the server's page signs in with sauuser's password, so it stops working from this step on. Your SSH sessions and the server's other controls are not affected.
Allow SSH first and only then enable the firewall, or enabling it ends your own session.
sudo apt install -y ufw
sudo ufw default deny incoming
sudo ufw default allow outgoing
sudo ufw allow OpenSSH
sudo ufw --force enable
sudo ufw status verbose
The status reads Status: active, Default: deny (incoming), allow (outgoing), deny (routed) and one rule pair for 22/tcp (OpenSSH). When the server later serves a website, open its ports with sudo ufw allow 80,443/tcp.
On Servers Are Up, nothing reaches the server from the internet until you turn an entry point on from its page or add a port forward, whatever this firewall allows. The firewall still matters: it is what stands between the server and the other machines on its private network.
unattended-upgrades installs updates from Ubuntu's security pocket once a day. The two settings below switch on the daily run.
sudo apt install -y unattended-upgrades
printf 'APT::Periodic::Update-Package-Lists "1";\nAPT::Periodic::Unattended-Upgrade "1";\n' | sudo tee /etc/apt/apt.conf.d/20auto-upgrades > /dev/null
sudo unattended-upgrade --dry-run --debug 2>&1 | grep 'Allowed origins'
The last line names the archives it installs from, and they include the security pocket: Allowed origins are: o=Ubuntu,a=noble, o=Ubuntu,a=noble-security, ....
From your second terminal, sign in with the key, then try a password sign-in on purpose:
ssh -p PORT deploy@SERVER_ADDRESS 'echo key sign-in works'
ssh -p PORT -o PubkeyAuthentication=no deploy@SERVER_ADDRESS
The first prints key sign-in works. The second is refused at once with Permission denied (publickey)., which means the server no longer offers password sign-in to anyone. Only now close the first terminal.
sudo asks for a password and none works. The user was created without one, or with a different one than you remember. From the account you started with, run sudo passwd deploy and set it again.sudo ls -la /home/deploy/.ssh on the server: the folder must read drwx------ deploy deploy and the file -rw------- deploy deploy, and the file must hold your public key on one line. A line broken in two when you pasted it is the usual cause.sudo systemctl reload ssh says the unit is not active. On Ubuntu 24.04 SSH starts on demand, and the service runs while someone is signed in over SSH. Run the step from an SSH session, or use sudo systemctl restart ssh.00- file in /etc/ssh/sshd_config.d/ rather than in sshd_config, so an update that replaces the main file keeps your settings./var/log/unattended-upgrades/unattended-upgrades.log now and then, and reboot when /var/run/reboot-required appears.Every Servers Are Up virtual machine and container includes an integrated HTML5 browser-based SSH, RDP, and VNC console in your dashboard, default-off inbound firewall rules with per-IP allow-lists, and full programmatic control via REST API v1 and Model Context Protocol (MCP). Explore our Virtual Datacenter Plans or reach out to Servers Are Up Support.