Base Server Hardening

These are the minimum security operations to perform on every new server before putting it into production.

02

Quick Checklist

OperationPriority
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
03

1. Update the System

bash
apt update && apt upgrade -y   # Debian/Ubuntu
dnf update -y                  # CentOS/AlmaLinux
04

2. Configure SSH Keys and Disable Passwords

bash
# On your computer: copy your public key
ssh-copy-id root@SERVER_IP

# On the server: disable password login
nano /etc/ssh/sshd_config

Set:

PasswordAuthentication no PermitRootLogin prohibit-password
bash
systemctl restart sshd
05

3. Enable the Firewall

bash
ufw default deny incoming
ufw default allow outgoing
ufw allow ssh
ufw allow http
ufw allow https
ufw enable
06

4. Install Fail2ban

bash
apt install fail2ban -y
systemctl enable --now fail2ban

See the complete guide: Fail2ban

07

5. Create a Non-Root User

bash
adduser deploy
usermod -aG sudo deploy
08

6. Configure Automatic Security Updates

bash
# Debian/Ubuntu
apt install unattended-upgrades -y
dpkg-reconfigure --priority=low unattended-upgrades
09

Complete Recommended SSH Configuration

bash
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 no
bash
systemctl restart sshd
10

Verify SSH Configuration

bash
sshd -T | grep -E 'passwordauth|permitroot|port|maxauthtries'
11

Monitor Access

Regularly check who has accessed your server:

bash
# Last successful logins
last | head -20

# Failed login attempts
lastb | head -20

# SSH logs in real-time
journalctl -u sshd -f
12

Automatic Security Audit Tool

You can use Lynis for automated security audit:

bash
apt install lynis -y
lynis audit system

Lynis analyzes your server configuration and suggests improvements with a security score.

DeluxHost, founded in 2023, offers high-quality hosting solutions for various digital needs. We provide shared hosting, VPS, and dedicated servers with advanced security and global data centers.

Β© DeluxHost, All rights reserved. | VAT Number : IT17734661006
All Systems Operational