First steps on a new Linux server
Five things to do right after your first login: update, create a user, use SSH keys, turn on the firewall and take a snapshot.
These commands are for Ubuntu and Debian. On AlmaLinux, Rocky Linux and Fedora use dnf instead of apt.
1. Install updates
apt update && apt upgrade -y2. Create your own user
Working as root all the time is risky. Create a user that can use sudo:
adduser alex
usermod -aG sudo alex3. Log in with a key, not a password
Add your SSH key (see "Connect to your Linux server with SSH"), check that you can log in with it, and only then turn password logins off. In /etc/ssh/sshd_config set:
PasswordAuthentication noThen restart SSH with systemctl restart ssh. Keep your current session open until a second login with the key has worked.
4. Turn on the firewall
ufw allow OpenSSH
ufw allow 80,443/tcp
ufw enableOpen only the ports you really use.
5. Take a snapshot
When the server is set up the way you want, take a snapshot on the server's page. If something breaks later, you can return to this state.
Good to know
Outgoing connections on port 25 (mail delivery) are blocked on our Linux servers to prevent spam. To send email from your application, use a mail service through port 587 or its API.