This is the process which I use when setting up a new VPS before it touches or does anything
This guide is based off of Debian 13, so should work with similar Debian versions and Debian based distros like Ubuntu
Initial Server Setup & Hardening
SSH into the machine using the root user/pass
ssh root@ip -p 22Update:
apt update && apt upgrade -yCreate a non-root user:
adduser viper # create user usermod -aG sudo viper # adds user to sudo group su viper # su = switch userInsert password then click enter to default others
exit exit # again to get out of suThen log into ssh using your new user
ssh viper@ip -p 22Enable automatic security updates:
sudo apt install unattended-upgrades -y sudo dpkg-reconfigure unattended-upgradesIf using windows:
ssh-keygen -t ed25519 -C "vipervps"Click enter to set defaults
Move the key to the server:
type $env:USERPROFILE\.ssh\id_ed25519.pub | ssh viper@ip "mkdir -p ~/.ssh && chmod 700 ~/.ssh && cat >> ~/.ssh/authorized_keys && chmod 600 ~/.ssh/authorized_keys"Ensure it works
exitssh viper@ipSSH Hardening
sudo vim /etc/ssh/sshd_configApply the following:
Port 2200 PermitRootLogin no PasswordAuthentication no PubkeyAuthentication yes AllowUsers viperRestart ssh
sudo systemctl restart ssh # (or sshd)Usually best here to open a new terminal and attempt to connect before you lock yourself out, if you do most VPS providers have a rescue option
UFW Firewall
Install:
sudo apt install ufw -yDefault Policies:
sudo ufw default deny incoming sudo ufw default allow outgoingAllow SSH:
sudo ufw allow 2200/tcp comment 'SSH'If hosting web servers:
sudo ufw allow 80/tcp sudo ufw allow 443/tcpEnable UFW:
sudo ufw enableCheck UFW status:
sudo ufw status verboseBasic Kernel and Network Hardening: disabling ICMP redirects, source routing and broadcast pings, enabling SYN cookie protection against SYN flood DDoS attacks
sudo vim /etc/sysctl.confAdd the following:
net.ipv4.conf.all.accept_redirects = 0 net.ipv4.conf.default.accept_redirects = 0 net.ipv4.conf.all.send_redirects = 0 net.ipv4.conf.default.send_redirects = 0 net.ipv4.conf.all.accept_source_route = 0 net.ipv4.conf.default.accept_source_route = 0 net.ipv4.icmp_echo_ignore_broadcasts = 1 net.ipv4.tcp_syncookies = 1Apply
sudo sysctl -p
The VPS now should be pretty secure
Installing Nginx & Hosting a Static Site
Nginx Install:
sudo apt install nginx -yFirewall allow web traffic:
sudo ufw allow 'Nginx Full'Put website files into
/var/www/site-herePut config into sites-available
sudo vim site-configserver { listen 80; listen [::]:80; server_name domain-here.com www.domain-here.com; root /var/www/site-here; index index.html index.htm; location / { try_files $uri $uri/ =404; } }Enable the site
sudo ln -s /etc/nginx/sites-available/site-config /etc/nginx/sites-enabled/ sudo rm /etc/nginx/sites-enabled/defaultTest and reload
sudo nginx -t sudo systemctl reload nginxAdd HTTPS with Let’s Encrypt
sudo apt install certbot python3-certbot-nginx -y sudo certbot --nginx -d domain-here.com -d www.domain-here.com
and ur done!