Security
Base Server Hardening
Checklist of fundamental security operations to secure a new VPS before putting it into production
These are the minimum security operations to perform on every new server before putting it into production.
Quick Checklist
| Operation | Priority |
|---|---|
| Update system | 🔴 Critical |
| Change root password | 🔴 Critical |
| Configure SSH keys | 🔴 Critical |
| Enable firewall | 🔴 Critical |
| Install Fail2ban | 🟠 High |
| Disable SSH password login | 🟠 High |
| Create non-root user | 🟠 High |
| Change SSH port | 🟡 Medium |
| Configure automatic updates | 🟡 Medium |
1. Update the System
apt update && apt upgrade -y # Debian/Ubuntu
dnf update -y # CentOS/AlmaLinux2. Configure SSH Keys and Disable Passwords
# On your computer: copy your public key
ssh-copy-id root@SERVER_IP
# On the server: disable password login
nano /etc/ssh/sshd_configSet:
PasswordAuthentication no
PermitRootLogin prohibit-passwordsystemctl restart sshd3. Enable the Firewall
ufw default deny incoming
ufw default allow outgoing
ufw allow ssh
ufw allow http
ufw allow https
ufw enable4. Install Fail2ban
apt install fail2ban -y
systemctl enable --now fail2banSee the complete guide: Fail2ban
5. Create a Non-Root User
adduser deploy
usermod -aG sudo deploy6. Configure Automatic Security Updates
# Debian/Ubuntu
apt install unattended-upgrades -y
dpkg-reconfigure --priority=low unattended-upgradesComplete Recommended SSH Configuration
nano /etc/ssh/sshd_config# Change the port (optional)
Port 2222
# Disable root login with password
PermitRootLogin prohibit-password
# Disable password authentication
PasswordAuthentication no
# Disable interactive keyboard authentication
ChallengeResponseAuthentication no
# Disable X11 forwarding if not needed
X11Forwarding no
# Limit authentication attempts
MaxAuthTries 3
# Timeout for idle sessions (in seconds)
ClientAliveInterval 300
ClientAliveCountMax 2
# Disable login for users without password
PermitEmptyPasswords nosystemctl restart sshdVerify SSH Configuration
sshd -T | grep -E 'passwordauth|permitroot|port|maxauthtries'Monitor Access
Regularly check who has accessed your server:
# Last successful logins
last | head -20
# Failed login attempts
lastb | head -20
# SSH logs in real-time
journalctl -u sshd -fAutomatic Security Audit Tool
You can use Lynis for automated security audit:
apt install lynis -y
lynis audit systemLynis analyzes your server configuration and suggests improvements with a security score.