How to secure VPS configuration on Contabo
Secure your Contabo VPS by enabling 2FA on CCP and SSH, configuring restrictive firewall rules for SSH/HTTP/HTTPS from trusted IPs, using key-based authentication, disabling unnecessary services, and applying regular patches. Follow the principle of least privilege to minimize attack surface. Regularly review logs and backup configurations.
Prerequisites
- Access to Contabo Customer Control Panel (CCP)
- SSH or RDP access to your VPS
- Smartphone for 2FA apps like Google Authenticator
- Basic Linux/Windows admin knowledge
- Root/admin privileges on VPS
Step-by-Step Instructions
Enable 2FA on Contabo CCP
Set Up SSH Key-Based Authentication
~/.ssh/authorized_keys on the VPS, and disable password authentication in /etc/ssh/sshd_config by setting PasswordAuthentication no. Restart SSH with sudo systemctl restart sshd. Refer to Contabo's 'How to Use SSH Keys with Your Server' guide.Configure Restrictive Firewall Rules
port 22) only from trusted IP addresses, HTTP/HTTPS (ports 80/443) for web services, and block all other inbound traffic by default. Example: iptables -A INPUT -p tcp --dport 22 -s <trusted_ip> -j ACCEPT
iptables -P INPUT DROP Apply the principle of least privilege.Enable 2FA for SSH Access
/etc/ssh/sshd_config to enable ChallengeResponseAuthentication yes and AuthenticationMethods publickey,keyboard-interactive. Install Google Authenticator with sudo apt install libpam-google-authenticator, run google-authenticator, and restart SSH service. You'll be prompted for a time-based code on login.Disable Unnecessary Services
systemctl list-units --type=service on Linux to list services, then disable with sudo systemctl disable <service_name> && sudo systemctl stop <service_name>. Scan exposed ports with tools like Shodan, Censys, or nmap to confirm only required services are running.Enable Firewall Logging and Backups
-j LOG to rules before DROP. Review logs regularly with journalctl or /var/log/syslog. Backup rules before changes using iptables-save > firewall_backup.rules and restore with iptables-restore to prevent misconfigurations.Keep System Updated and Patched
sudo apt update && sudo apt upgrade -y. Schedule maintenance, test updates in staging, and monitor vendor security patches. This mitigates risks from known exploits.Configure RDP 2FA (Windows VPS)
Implement Data Encryption
cryptsetup luksFormat /dev/sdX and open with cryptsetup luksOpen. Review encryption settings periodically to ensure confidentiality against breaches.Install Fail2Ban for Brute-Force Protection
sudo apt install fail2ban. Configure jails for SSH and other services in /etc/fail2ban/jail.local to ban IPs after failed attempts. It monitors logs and updates iptables dynamically.Common Issues & Troubleshooting
Locked out after firewall changes
Use Contabo VNC console in CCP to access VPS, revert rules with <code>iptables -F</code>, or restore from backup.
SSH 2FA not prompting
Verify <code>pam_google_authenticator.so</code> in <code>/etc/pam.d/sshd</code> and <code>ChallengeResponseAuthentication yes</code> in sshd_config; restart sshd.
Exposed services detected by scans
Disable unnecessary services with systemctl, reconfigure firewall to block ports, rescan with nmap.
Cannot restore iptables rules
Ensure <code>iptables-persistent</code> is installed and rules saved; reboot may reset if not persistent.
Fail2Ban not banning IPs
Check <code>fail2ban-client status sshd</code>, review logs in <code>/var/log/fail2ban.log</code>, adjust maxretry in jail.local.