How Do I Secure My VPS Server? Print

  • Secure VPS, Hardening, Server Security, Firewall, Fail2ban
  • 0

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) or usermod -aG wheel yourusername (CentOS/Alma).

  • Then, edit the SSH config file (nano /etc/ssh/sshd_config) and set PermitRootLogin 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/tcpufw allow 443/tcp, then ufw 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.


Was this answer helpful?

« Back

Powered by WHMCompleteSolution