A new server on the internet is found by automated scanners within minutes. These steps take about 15 minutes and stop most attacks. They are written for Ubuntu and Debian. Run them while logged in as root.
1. Install updates
apt update && apt upgrade -y
2. Turn on automatic security updates
apt install -y unattended-upgrades
dpkg-reconfigure --priority=low unattended-upgrades
Choose Yes when asked.
3. Create your own user
Working as root all the time is risky: one wrong command can break everything. Create a normal user that can become administrator when needed. Replace sam with a name you like:
adduser sam
usermod -aG sudo sam
Copy your SSH key to the new user (see the SSH keys guide), for example from your own computer:
ssh-copy-id sam@203.0.113.10
4. Turn on the firewall
The firewall blocks everything except what you allow. Allow SSH first, or you will lock yourself out:
ufw allow OpenSSH
ufw enable
For a website, also allow web traffic:
ufw allow 80,443/tcp
5. Switch off password login and root login
Only do this after your SSH key works for your new user. Keep your current window open, and test in a second window before closing it.
printf "PasswordAuthentication no\nPermitRootLogin no\n" > /etc/ssh/sshd_config.d/00-hardening.conf
sshd -t && systemctl restart ssh
Now open a new window and check that you can still log in:
ssh sam@203.0.113.10
From now on, run administrator commands with sudo in front, for example sudo apt update.
Locked out?
Contact support. We can help you get back in through the server console.
NarHosts