With great power comes great responsibility. On a VPS, you are the system administrator, so securing your server is critical. Here are the essential first steps.
1. Update Your System
Always start with a fully updated system.
-
For Debian/Ubuntu:
apt update && apt upgrade -y -
For CentOS/AlmaLinux:
yum update -y
2. Create a New User (Disable Root Login)
It is dangerous to log in as root daily.
-
Create a new user:
adduser yourusername -
Give them sudo privileges:
usermod -aG sudo yourusername(Ubuntu) orusermod -aG wheel yourusername(CentOS/Alma). -
Then, edit the SSH config file (
nano /etc/ssh/sshd_config) and setPermitRootLogin no. Restart SSH:systemctl restart sshd.
3. Change the Default SSH Port
Edit /etc/ssh/sshd_config and change the Port 22 line to a higher number (e.g., Port 2222). Remember this new port for future logins!
4. Set Up a Firewall
Use UFW (easy) or CSF (ConfigServer Security & Firewall).
-
UFW Example:
ufw allow 2222/tcp(your new SSH port),ufw allow 80/tcp,ufw allow 443/tcp, thenufw enable.
5. Install Fail2ban
This tool bans IPs after repeated failed login attempts.
-
Install:
apt install fail2ban -y -
It works automatically once installed, protecting SSH.