VPS security essentials

Hardening your virtual server against external threats.

Securing a VPS is a continuous process that begins the moment the operating system is installed. Properly configuring access barriers and monitoring systems is the only way to minimize the risks of unauthorized access and data loss.

Locking down access with a firewall

A firewall acts as a critical filter between the global network and your server. It inspects incoming and outgoing traffic based on a predefined set of rules, allowing data to pass only through authorized ports.

Typically, a server only needs a few open ports (e.g., 80 and 443 for web traffic). Every other unused port should be strictly closed to reduce the attack surface.

  • UFW (Uncomplicated Firewall) — a user-friendly interface designed to manage rules without complex syntax. Basic setup for Ubuntu/Debian:

    sudo apt update
    sudo apt install ufw
    sudo ufw allow OpenSSH     # Or your custom SSH port
    sudo ufw allow 80/tcp      # HTTP
    sudo ufw allow 443/tcp     # HTTPS
    sudo ufw enable
    sudo ufw status
    
  • IPTables — a veteran Linux utility for managing the NetFilter kernel component. It offers immense flexibility and is battle-tested. For IPv6 traffic, use the ip6tables version. Example:

    sudo iptables -P INPUT DROP
    sudo iptables -P FORWARD DROP
    sudo iptables -P OUTPUT ACCEPT
    sudo iptables -A INPUT -i lo -j ACCEPT
    sudo iptables -A INPUT -m conntrack --ctstate ESTABLISHED,RELATED -j ACCEPT
    sudo iptables -A INPUT -p tcp --dport 22 -j ACCEPT    # SSH
    sudo iptables -A INPUT -p tcp --dport 80 -j ACCEPT
    sudo iptables -A INPUT -p tcp --dport 443 -j ACCEPT
    sudo iptables-save > /etc/iptables.rules
    

Hardening remote access with SSH

The SSH (Secure Shell) protocol is the industry standard for remote Linux administration. It provides end-to-end encryption for commands, file transfers, and even GUI tunneling.

Passwords vs SSH keys

Relying on standard passwords leaves your server vulnerable to "brute-force" attacks, where bots automatically cycle through millions of character combinations.

SSH Key authentication is a significantly more robust method:

  1. Public key — stored on the server to identify you.
  2. Private key — kept securely on your local machine and protected by a passphrase.

Due to their cryptographic complexity, these keys are virtually impossible to crack using traditional methods.

Mitigating malicious activity with Fail2ban

Fail2ban is an automated service that scans system logs (like SSH login attempts) for suspicious patterns. If an IP address fails to authenticate multiple times, Fail2ban dynamically updates your firewall to "jail" that address, temporarily or permanently banning its traffic.

Implementing Intrusion Detection Systems (IDS)

An IDS acts as a silent alarm, notifying you if your primary defenses are breached. These systems catalog the "clean" state of your files and configurations, then alert you if any unauthorized changes occur.

File integrity monitoring:

  • Tripwire — one of the most respected systems available. It builds a database of system files and signs it with cryptographic keys to detect any tampering.
  • Aide — a lightweight and effective alternative to Tripwire, using file attribute comparison to verify integrity.

Network and threat monitoring:

  • Psad — monitors firewall logs to detect port scans and other "noisy" network activity.
  • Bro (Zeek) — a powerful network analysis engine that records rich metadata to identify anomalous traffic patterns.
  • RKHunter (Rootkit Hunter) — a specialized tool designed to hunt for rootkits, backdoors, and common local exploits.

General security best practices

  • Update regularly: run sudo apt update && sudo apt upgrade -y to patch vulnerabilities.
  • Minimize software: install only the packages essential for your specific tasks.
  • Enforce complexity: always use high-entropy passwords or keys.
  • Audit services: disable any background services that are not in use.
  • Enable 2FA: always use Two-Factor Authentication on your hosting provider's control panel.
  • Maintain backups: ensure you have regular, off-site backups that are not stored solely on the server itself.

Pro tip

Start your security journey by enabling UFW and switching to SSH Keys. These two steps alone will neutralize over 90% of automated attacks targeting new servers.

Help

If you have any questions or need assistance, please contact us through the ticket system — we're always here to help!

Updated at:
Need help?Our engineers will help you free of charge with any question in minutesContact us