This guide explains how to secure a production VPS server using industry-standard practices. It covers system updates, automatic security upgrades, non-root user setup, SSH key-based authentication, SSH hardening, firewall configuration using UFW, brute-force protection with Fail2Ban, and optional two-factor authentication. The steps are designed to reduce attack surface and improve server security without complex tooling.
Dec 5, 2025
By Viral Mistry

This guide covers basic but essential production-level VPS security for Ubuntu/Debian servers. Follow the steps in order to avoid accidental lockout.
Always update package lists before installing anything.
shellapt update
Automatically installs critical security patches.
shellapt install unattended-upgrades
shelldpkg-reconfigure --priority=low unattended-upgrades
Never use the root user for daily operations.
shelladduser <username>
Grant sudo access.
shellusermod -aG sudo <username>
Logout from root.
shelllogout
Login using the new user.
shellssh <username>@ip
SSH keys are more secure than passwords.
Create SSH directory on server.
shellmkdir ~/.ssh && chmod 700 ~/.ssh
Generate SSH key on your local machine.
shellssh-keygen -t ed25519 -C "your_email@example.com"
Add a passphrase if you want extra protection.
Go to .ssh directory on your local machine.
shellcd .ssh
Copy public key to server (Windows).
powershellscp $env:USERPROFILE/.ssh/id_rsa.pub <username>@ip:~/.ssh/authorized_keys
Copy public key to server (Linux / macOS).
bashscp ~/.ssh/id_rsa.pub <username>@ip:~/.ssh/authorized_keys
Edit /etc/ssh/sshd_config and apply the following changes:
textPort 717 AddressFamily inet PermitRootLogin no PasswordAuthentication no
Restart SSH service.
shellsudo systemctl restart sshd
Login using the new port.
shellssh username@ip -p <portnumber>
Check open ports.
shellsudo ss -tupln
Install UFW.
shellsudo apt install ufw
Check firewall status.
shellsudo ufw status
Allow custom SSH port.
shellsudo ufw allow 717
Enable firewall.
shellsudo ufw enable
Edit UFW rules for ICMP.
shellsudo nano /etc/ufw/before.rules
Block ping requests (optional).
text-A ufw-before-input -p icmp --icmp-type echo-request -j DROP
Reboot server.
shellsudo reboot
Protects against brute-force SSH attacks.
shellsudo apt install fail2ban -y
Create local config.
shellsudo nano /etc/fail2ban/jail.local
Basic SSH jail configuration.
text[sshd] enabled = true port = <your-port> maxretry = 3 bantime = 15m
Restart Fail2Ban.
shellsudo systemctl restart fail2ban
Check status.
shellsudo systemctl status fail2ban
View active jails.
shellsudo fail2ban-client status
Adds two-factor authentication for SSH.
shellsudo apt install libpam-google-authenticator google-authenticator
Disable password authentication for a specific user.
textMatch User divya PasswordAuthentication no
Built with Next.js