Last updated
Initial Server Setup With Ubuntu 24.04 and 22.04
The first five things to do on a new Ubuntu server: update it, create a normal user with sudo, set up SSH keys, turn on the firewall and enable automatic security updates. Works on Ubuntu 24.04, 22.04 and 20.04.
Related guide: Full Ubuntu server setup guide
1. Log in and update
Log in as root (or the default user your provider created) and install updates.
ssh root@your_server_ip
apt update && apt upgrade -y
2. Create a normal user with sudo
Do daily work as a normal user. Replace deploy with your user name.
adduser deploy
usermod -aG sudo deploy
3. Copy your SSH key to the new user
If you logged in as root with a key, copy it across so the new user can log in with it.
rsync --archive --chown=deploy:deploy ~/.ssh /home/deploy
4. Turn on the firewall
Allow SSH first, then enable UFW.
ufw allow OpenSSH
ufw enable
ufw status
5. Automatic security updates
unattended-upgrades installs security fixes for you every day.
apt install unattended-upgrades
dpkg-reconfigure --priority=low unattended-upgrades
6. Test before you log out
Open a new terminal and log in as the new user, then check sudo works.
ssh deploy@your_server_ip
sudo whoami # root
FAQ
Should I disable root login over SSH?
Yes, once your sudo user can log in with a key. Set PermitRootLogin no in a file under /etc/ssh/sshd_config.d/ and restart SSH.
Why use a normal user instead of root?
Mistakes and malicious scripts can do far less damage, and sudo leaves a log of admin commands.