Secure Your Hostinger VPS: Fail2Ban, SSL, and Firewall Guide
Securing a Hostinger VPS involves five layers: SSH hardening (key-only auth, disable root login), UFW firewall (allow only needed ports), Fail2Ban (block brute-force attempts), SSL with Let's Encrypt (HTTPS for all web services), and automatic security updates (unattended-upgrades). Complete this setup once and your server is protected against 99% of common attacks.
Step 1: SSH Hardening
SSH hardening: use ed25519 keys, disable root login, disable password auth, limit max auth tries. Always verify key login works before disabling passwords.
SSH is the most common attack surface. Harden it immediately:
# First, set up SSH keys (on your LOCAL machine)
ssh-keygen -t ed25519 -C "your-email@example.com"
ssh-copy-id root@YOUR_SERVER_IP
# Test key login works before disabling passwords!
ssh root@YOUR_SERVER_IP
# Now edit SSH config on the server
nano /etc/ssh/sshd_config
# Change/add these settings:
PermitRootLogin no # Disable root SSH login
PasswordAuthentication no # Require SSH keys only
X11Forwarding no
MaxAuthTries 3
Port 22 # Optional: change to a non-standard port
# Restart SSH
systemctl restart sshdWarning: Test that your SSH key works before disabling password auth. Getting locked out requires console access through Hostinger's panel.
Step 2: UFW Firewall Configuration
UFW (Uncomplicated Firewall) provides simple iptables management:
# Install UFW
apt install ufw -y
# Set default policies
ufw default deny incoming
ufw default allow outgoing
# Allow SSH (critical — don't skip!)
ufw allow 22/tcp
# If you changed SSH port:
# ufw allow YOUR_NEW_PORT/tcp
# Allow HTTP and HTTPS
ufw allow 80/tcp
ufw allow 443/tcp
# Enable firewall
ufw enable
# Verify
ufw status verboseOnly open ports you actively use. Each open port is a potential attack vector. If you're running a game server, database, or other services, add their ports explicitly.
Step 3: Fail2Ban — Block Brute Force Attacks
Fail2Ban monitors logs and bans IPs that show malicious behavior:
# Install Fail2Ban
apt install fail2ban -y
# Create a local config (don't edit jail.conf directly)
cat > /etc/fail2ban/jail.local << 'EOF'
[DEFAULT]
bantime = 3600
findtime = 600
maxretry = 5
[sshd]
enabled = true
port = 22
logpath = /var/log/auth.log
maxretry = 3
[nginx-http-auth]
enabled = true
[nginx-limit-req]
enabled = true
EOF
# Start Fail2Ban
systemctl enable fail2ban
systemctl start fail2ban
# Check status
fail2ban-client status
fail2ban-client status sshdFail2Ban will automatically ban any IP that fails SSH login 3 times within 10 minutes, for 1 hour. You can adjust these thresholds in jail.local.
Step 4: Automatic Security Updates
Keep your server patched without manual intervention:
# Install unattended-upgrades
apt install unattended-upgrades -y
# Configure to apply security updates automatically
cat > /etc/apt/apt.conf.d/20auto-upgrades << 'EOF'
APT::Periodic::Update-Package-Lists "1";
APT::Periodic::Unattended-Upgrade "1";
APT::Periodic::AutocleanInterval "7";
EOF
# Verify configuration
unattended-upgrades --dry-run --debug 2>&1 | head -20Step 5: SSL Everywhere
Never expose services over HTTP. Use Traefik (for Docker apps) or Certbot (for traditional apps) for automatic SSL:
# For traditional Nginx/Apache apps:
apt install certbot python3-certbot-nginx -y
certbot --nginx -d yourdomain.com -d www.yourdomain.com
# Auto-renew is set up automatically by Certbot
# Test renewal:
certbot renew --dry-runFor Docker-based deployments, use Traefik as shown in the Docker guide — it handles SSL automatically for every container you label.
Additional Security Recommendations
- Create a non-root user: Never run your applications as root
- Regular backups: A compromised server you can restore from is recoverable; one without backups is not
- Monitoring: Set up UptimeRobot and check auth logs regularly (
tail -f /var/log/auth.log) - Docker security: Don't run containers as root, use read-only mounts where possible
- Disable unused services:
systemctl list-units --type=service --state=active— disable anything you don't recognize
Frequently Asked Questions
Is a Hostinger VPS secure by default?
The base Ubuntu 22.04 install is reasonably configured, but a fresh VPS needs security hardening before exposing it to the internet. At minimum: set up SSH keys, configure a firewall, and install Fail2Ban. This guide covers all steps.
What is Fail2Ban and do I need it?
Fail2Ban monitors login attempts and automatically bans IPs that fail repeatedly. Without it, bots will attempt thousands of SSH logins per day against your VPS. With SSH keys only (no passwords), brute force is impossible, but Fail2Ban adds an extra layer for application-level attacks.
Should I change the default SSH port?
Optional — changing from port 22 reduces automated scanning noise in logs. It's security through obscurity, not real security. SSH keys with Fail2Ban are more important. If you change the port, update UFW rules and ensure you can still connect before restarting SSH.
How do I know if my VPS has been compromised?
Signs: unusual CPU/memory usage, unexpected outbound network traffic, unfamiliar processes in 'top' or 'ps aux', failed login attempts in /var/log/auth.log, or files modified unexpectedly. Set up rkhunter and AIDE for automated intrusion detection.
Does Hostinger provide any built-in security?
Hostinger provides network-level DDoS mitigation and their firewall manager in the VPS panel. However, application-level security (SSH hardening, Fail2Ban, SSL) is your responsibility as the server administrator.
- 1
Harden SSH
Generate ed25519 SSH keys, copy to server, then disable password authentication and root login in sshd_config.
- 2
Configure UFW firewall
Set default deny incoming, allow only SSH, HTTP (80), and HTTPS (443). Enable UFW.
- 3
Install Fail2Ban
Install fail2ban, create jail.local with SSH and web server jails, enable and start the service.
- 4
Enable automatic updates
Install unattended-upgrades and configure to automatically apply security patches daily.
- 5
Add SSL everywhere
Use Certbot for traditional apps or Traefik for Docker. Never expose HTTP services publicly.
Secure Server + Great Price — Hostinger VPS
Start with a clean VPS and follow this guide. Hostinger KVM 1 from $4.99/mo.
Try Hostinger VPSHenry Fontaine
Chief of Staff & COO, RocketLabs
AI-native operator building the future of search visibility. Part of the team behind 3 tech exits and 400+ programmatic SEO deployments.