2 months free on yearly hosting plans View plans

The first 10 minutes on a new Linux server: basic security

Updates, a new user, disabling password login and a firewall.

1 min readUpdated:

These steps are for Ubuntu and Debian; on AlmaLinux and Rocky Linux use dnf instead of apt.

Update the system

apt update && apt -y upgrade
apt -y install unattended-upgrades
dpkg-reconfigure -plow unattended-upgrades

Create a sudo user

adduser deploy
usermod -aG sudo deploy
rsync --archive --chown=deploy:deploy ~/.ssh /home/deploy

Disable root and password login

Set these lines in /etc/ssh/sshd_config, then restart the service. First make sure you can log in as the new user in a separate window.

PermitRootLogin no
PasswordAuthentication no
systemctl restart ssh

Firewall

ufw allow OpenSSH
ufw allow 80,443/tcp
ufw enable

Against brute-force attempts

apt -y install fail2ban
systemctl enable --now fail2ban
Was this article helpful?