Before a new server goes into production, log in as root and change the password, update all packages and create your own user with sudo rights. Then switch SSH to key-based login and enable a firewall that only opens the ports you need.
Key facts
- Time needed
- about 20 minutes
- Prerequisite
- credentials from the customer panel
- First access
- SSH on port 22
- Most important step
- disable password login
- Firewall
- ufw or nftables
- Afterwards
- automatic security updates
1. Log in and change the credentials
Once the server is provisioned, the credentials are in the customer panel. Log in over SSH and set a new root password straight away. The delivered password was sent by email and should not stay in use.
- ssh root@<ip-address>
- passwd
2. Update the system
A freshly provisioned image is rarely up to date. Install all updates first so known vulnerabilities are closed before any service starts.
- Debian and Ubuntu: apt update && apt full-upgrade
- Rocky, AlmaLinux and RHEL: dnf upgrade --refresh
Then enable automatic security updates, with unattended-upgrades on Debian and Ubuntu and dnf-automatic on RHEL derivatives.
3. Create your own user
Do not work as root all the time. Create a user with sudo rights and use it for everyday work. A typo then does not immediately affect the whole system.
- adduser <name>
- usermod -aG sudo <name> (Debian/Ubuntu)
- usermod -aG wheel <name> (RHEL derivatives)
4. Switch SSH to keys
A password can be guessed, an SSH key practically cannot. Add your public key to the new user and then disable password login.
Test the key login in a second session before closing the first one, otherwise you lock yourself out. The detailed steps are in the article on SSH keys.
5. Set up a firewall
Open only the ports you need and keep all others closed. For a web server that usually means SSH plus 80 and 443.
- ufw default deny incoming
- ufw allow OpenSSH
- ufw allow 80,443/tcp
- ufw enable
What else is worth doing
For continuous operation, a few more points are worth doing. None of them take long.
- Check the time zone and NTP so logs stay comparable
- Set up a backup that does not live on the same server
- fail2ban against repeated login attempts
- Set reverse DNS if the server sends email
- Set up monitoring so you do not hear about outages from customers
Update, create your own user, switch SSH to keys and close the firewall. That prevents most of the incidents we see in support.