Back to articles
Technology Insight

VPS Security for Beginners: A 15-Point Mandatory Checklist After Purchase (SSH Key, Firewall, Fail2ban, Audit)

May 18, 2026

Introduction: The Critical First Hours of Your VPS

Purchasing a Virtual Private Server (VPS) is a significant step toward greater control, performance, and flexibility for your projects. However, a newly provisioned VPS is often a highly vulnerable target. Automated bots scan the internet continuously for fresh IP addresses, attempting to exploit default configurations and weak credentials within minutes of your server going live. The security posture you establish in the first few hours determines your long-term resilience. This guide provides a mandatory, actionable checklist of 15 steps to transform your exposed VPS into a hardened, secure environment suitable for production workloads.

1. Initial Login & Immediate User Security

Your very first action should be to log in and secure the primary access point.

1.1. Disable Root Login via Password

The root user is the universal target. Allowing password-based root login over SSH is one of the most common causes of server compromise.

  • Edit the SSH daemon configuration: sudo nano /etc/ssh/sshd_config
  • Find and change the line to: PermitRootLogin no
  • If you must have root SSH access (not recommended), use: PermitRootLogin prohibit-password (keys only)

1.2. Create a Dedicated Administrative User

Create a new, unprivileged user for daily operations, granting sudo privileges only when necessary.

  1. sudo adduser yourusername
  2. sudo usermod -aG sudo yourusername
  3. Log out and test logging in as the new user before proceeding.

2. Fortifying SSH Access: Beyond Passwords

Secure Shell (SSH) is your gateway; it must be impregnable.

2.1. Generate and Deploy SSH Key Pairs

Password authentication is vulnerable to brute-force attacks. SSH keys provide cryptographic strength.

  • On your local machine, generate a key pair: ssh-keygen -t ed25519 -a 100
  • Copy the public key to your VPS: ssh-copy-id yourusername@your_server_ip
  • Verify you can log in with the key before disabling passwords.

2.2. Harden the SSH Daemon Configuration

Edit /etc/ssh/sshd_config with these critical settings:

  • PasswordAuthentication no
  • PubkeyAuthentication yes
  • PermitEmptyPasswords no
  • Change the default port (optional but recommended): Port 2222 (or another non-standard port)
  • Protocol 2 (explicitly disable legacy Protocol 1)

Always test your configuration in a second terminal window before restarting the service: sudo sshd -t. Then apply: sudo systemctl restart sshd.

3. Building Your First Line of Defense: The Firewall

A firewall controls network traffic to and from your server, blocking everything except what you explicitly allow.

3.1. Configure UFW (Uncomplicated Firewall)

UFW provides a user-friendly interface for iptables. Start by denying all incoming traffic by default.

  1. Enable UFW: sudo ufw enable (be cautious—ensure SSH is allowed first!).
  2. Set default policies: sudo ufw default deny incoming and sudo ufw default allow outgoing.
  3. Allow SSH on your configured port: sudo ufw allow 2222/tcp (or 22 if using default).
  4. Allow HTTP/HTTPS for web servers: sudo ufw allow 80,443/tcp.
  5. Check the rules: sudo ufw status verbose.

3.2. Firewall Best Practices

Only open ports that are absolutely necessary. Regularly review your rules with sudo ufw status numbered and remove any that are obsolete. For application-specific firewalls, consider firewalld (common on RHEL/CentOS) or direct iptables management for complex scenarios.

4. Active Intrusion Prevention with Fail2ban

Fail2ban monitors log files for patterns of malicious activity (like repeated failed SSH login attempts) and automatically updates the firewall to ban the offending IP addresses for a specified time.

4.1. Installation and Basic Configuration

  • Install: sudo apt install fail2ban (Debian/Ubuntu) or sudo yum install fail2ban (RHEL/CentOS).
  • Copy the default configuration: sudo cp /etc/fail2ban/jail.conf /etc/fail2ban/jail.local.
  • Edit jail.local to customize bans. Key parameters for the [sshd] jail:
    • bantime = 1h (or 10m for a shorter initial ban)
    • findtime = 10m (time window for counting failures)
    • maxretry = 3 (number of failures before a ban)

4.2. Monitoring and Customization

Start and enable the service: sudo systemctl start fail2ban and sudo systemctl enable fail2ban. Check its status with sudo fail2ban-client status sshd. You can extend Fail2ban to protect other services like web servers (nginx/apache) or FTP by creating custom filter rules in /etc/fail2ban/filter.d/ and enabling them in the jail configuration.

5. Essential System Hardening and Updates

A secure foundation requires a patched and minimally exposed system.

5.1. Enforce Automatic Security Updates

Configure unattended-upgrades to automatically install security patches.

  • On Debian/Ubuntu: sudo apt install unattended-upgrades and configure /etc/apt/apt.conf.d/50unattended-upgrades.
  • Enable: sudo dpkg-reconfigure --priority=low unattended-upgrades.
  • On RHEL/CentOS 7+: Use yum-cron. On RHEL 8+/CentOS Stream, use dnf-automatic.

5.2. Remove Unused Network Services

Reduce your attack surface by disabling services you don't need.

  1. Check listening ports: sudo ss -tulpn or sudo netstat -tulpn.
  2. Identify and stop/disable any unnecessary services (e.g., old mail servers, unused database sockets).
  3. Use: sudo systemctl stop service_name and sudo systemctl disable service_name.

6. Proactive Monitoring and Auditing

Security is not a one-time task. Continuous monitoring is key to early threat detection.

6.1. Install and Configure an Intrusion Detection System (IDS)

A host-based IDS like AIDE (Advanced Intrusion Detection Environment) or Tripwire creates a database of file checksums and attributes, alerting you to unauthorized changes.

  • Install AIDE: sudo apt install aide or sudo yum install aide.
  • Initialize the database: sudo aideinit and sudo mv /var/lib/aide/aide.db.new /var/lib/aide/aide.db.
  • Schedule daily checks via cron: sudo crontab -e and add: 0 5 * * * /usr/bin/aide --check.

6.2. Regular Log Review and Centralization

Logs are your evidence. Review critical logs regularly:

  • Authentication logs: sudo tail -f /var/log/auth.log (Debian/Ubuntu) or /var/log/secure (RHEL/CentOS).
  • Fail2ban logs: sudo tail -f /var/log/fail2ban.log.
  • For production, consider a centralized log management solution like the ELK Stack (Elasticsearch, Logstash, Kibana) or Grafana Loki to aggregate and analyze logs from multiple servers.

7. Application-Specific Security Measures

Once the OS is secure, you must secure the software running on it.

7.1. Web Server Security (Nginx/Apache)

  • Run web servers as a non-root, dedicated user.
  • Disable server tokens (hide version numbers).
  • Implement security headers (Content-Security-Policy, X-Frame-Options, etc.).
  • Use strong TLS/SSL configurations (disable old protocols like SSLv3, use modern ciphers).

7.2. Database Security (MySQL/MariaDB, PostgreSQL)

  • Run the mysql_secure_installation or equivalent script immediately after installation.
  • Remove anonymous users and test databases.
  • Bind database services to localhost (127.0.0.1) only if the application is on the same server.
  • Use strong, unique passwords for database root/users.

8. Backup Strategy: Your Ultimate Safety Net

No security checklist is complete without a reliable backup and recovery plan. Assume your server will be compromised or fail.

  • What to backup: Configuration files (/etc/), web/application data, databases, and user home directories.
  • Frequency: Automate daily incremental backups and weekly full backups.
  • Tools: Use rsync for file backups, mysqldump or pg_dump for databases, and tools like BorgBackup or Restic for deduplicated, encrypted backups.
  • The 3-2-1 Rule: Maintain 3 copies of your data, on 2 different media, with 1 copy stored offsite (e.g., a different cloud provider or object storage).

Conclusion: Building a Culture of Security

Securing a VPS is an ongoing process, not a single event. This 15-point checklist provides the essential foundation. Begin by implementing steps 1 through 5 (SSH, Firewall, Fail2ban, Updates) immediately after purchase. Then, progressively integrate monitoring, auditing, and application hardening. Schedule regular reviews of your security posture—check logs, update rules, and test your backups. By adopting these practices, you move from being a passive target to an active defender of your digital infrastructure. The effort invested in these initial configurations pays exponential dividends in stability, reliability, and peace of mind as your projects grow.

Remember: The most secure server is the one you understand and actively manage. Automation handles the routine, but vigilance and continuous learning are your greatest assets in cybersecurity.