Linux Server Setup
19 items · Technical · Hard difficulty · 1 hour
Securely set up a new Linux VPS with essential hardening steps.
-
Log in as root via SSH
SSH to the server using its IP: ssh root@SERVER_IP (or use provided console access).
-
Change the root password
Run passwd to set a strong, unique root password or rely on keys.
-
Update package list and upgrade installed packages
Run apt update && apt upgrade -y to apply latest security fixes.
-
Create a new sudo user
Use adduser username to create an account for daily admin tasks.
-
Set a strong password for the new user
Choose a long, unique password or rely on SSH keys for the account.
-
Add the new user to the sudo group
Run usermod -aG sudo username so the account can use sudo.
-
Set up SSH key authentication for the new user
Add your public key to /home/username/.ssh/authorized_keys with correct permissions.
-
Verify SSH key login as the new user
Test ssh username@SERVER_IP -i ~/.ssh/id_rsa and confirm shell access.
-
Disable root SSH login and password authentication
Edit /etc/ssh/sshd_config: set PermitRootLogin no and PasswordAuthentication no; reload sshd.
-
Configure UFW firewall
Use UFW to limit inbound access to only required services.
-
Allow OpenSSH through UFW
Run ufw allow OpenSSH before enabling the firewall to avoid lockout.
-
Allow HTTP and HTTPS through UFW
Run ufw allow 80/tcp and ufw allow 443/tcp for web services.
-
Enable UFW and verify status
Run ufw enable then ufw status verbose to confirm rules.
-
Install and enable fail2ban
apt install fail2ban; enable and start the service to ban repeated login failures.
-
Set timezone and locale
Use timedatectl set-timezone REGION and configure locale for correct logs.
-
Enable unattended security upgrades
Install unattended-upgrades and configure automatic security updates.
-
Create a swapfile
Add swap if the VM lacks it or needs more virtual RAM.
-
Allocate and secure the swapfile
fallocate -l 1G /swapfile; chmod 600 /swapfile (adjust size as needed).
-
Make the file swap, enable it, and add to fstab
Run mkswap, swapon and add an fstab entry; optionally set vm.swappiness.
Printed from TickYouOff — the interactive version tracks your progress and can be shared with others.