1. System aktualisieren
apt update && apt dist-upgrade -y
apt autoremove -y
# Unattended Upgrades für Sicherheits-Patches
apt install -y unattended-upgrades
dpkg-reconfigure --priority=low unattended-upgrades
# /etc/apt/apt.conf.d/50unattended-upgrades prüfen
# Sicherheits-Updates automatisch aktiviert
2. Neuen Admin-User erstellen (kein Root-Login!)
adduser admin
usermod -aG sudo admin
# SSH Key für neuen User
mkdir /home/admin/.ssh
cp /root/.ssh/authorized_keys /home/admin/.ssh/
chown -R admin:admin /home/admin/.ssh
chmod 700 /home/admin/.ssh
chmod 600 /home/admin/.ssh/authorized_keys
3. SSH absichern
# /etc/ssh/sshd_config anpassen:
sed -i 's/^#PermitRootLogin.*/PermitRootLogin no/' /etc/ssh/sshd_config
sed -i 's/^#PasswordAuthentication.*/PasswordAuthentication no/' /etc/ssh/sshd_config
sed -i 's/^#Port 22/Port 2222/' /etc/ssh/sshd_config
# Oder vollständige Konfiguration
cat >> /etc/ssh/sshd_config.d/hardening.conf << 'EOF'
Port 2222
PermitRootLogin no
PasswordAuthentication no
PubkeyAuthentication yes
MaxAuthTries 3
MaxSessions 5
AllowUsers admin
ClientAliveInterval 300
ClientAliveCountMax 2
X11Forwarding no
AllowAgentForwarding no
AllowTcpForwarding no
EOF
systemctl restart sshd
# Testen (in neuem Terminal!)
ssh -p 2222 admin@SERVER_IP
4. UFW Firewall
apt install -y ufw
# Standard: alles blockieren, ausgehend erlauben
ufw default deny incoming
ufw default allow outgoing
# Erlaubte eingehende Verbindungen
ufw allow 2222/tcp comment "SSH"
ufw allow 80/tcp comment "HTTP"
ufw allow 443/tcp comment "HTTPS"
# UFW aktivieren
ufw enable
# Status
ufw status verbose
5. Fail2ban
apt install -y fail2ban
cat > /etc/fail2ban/jail.local << 'EOF'
[DEFAULT]
bantime = 3600
findtime = 600
maxretry = 5
[sshd]
enabled = true
port = 2222
filter = sshd
logpath = /var/log/auth.log
maxretry = 3
bantime = 86400
[nginx-http-auth]
enabled = true
EOF
systemctl enable --now fail2ban
# Gebannte IPs
fail2ban-client status sshd
6. Kernel-Härtung (sysctl)
cat > /etc/sysctl.d/99-hardening.conf << 'EOF'
# IP-Spoofing verhindern
net.ipv4.conf.all.rp_filter = 1
net.ipv4.conf.default.rp_filter = 1
# ICMP Redirect ignorieren
net.ipv4.conf.all.accept_redirects = 0
net.ipv4.conf.default.accept_redirects = 0
# SYN Flood verhindern
net.ipv4.tcp_syncookies = 1
# IPv6 Redirects deaktivieren
net.ipv6.conf.all.accept_redirects = 0
# ASLR aktivieren
kernel.randomize_va_space = 2
# Core Dumps deaktivieren
fs.suid_dumpable = 0
EOF
sysctl -p /etc/sysctl.d/99-hardening.conf
7. Auditd installieren
apt install -y auditd
# Wichtige Events überwachen
auditctl -w /etc/passwd -p wa -k passwd-changes
auditctl -w /etc/sudoers -p wa -k sudoers-changes
auditctl -w /var/log -p wa -k log-changes
# Audit-Log lesen
ausearch -k passwd-changes | aureport --file
# Automatisch beim Boot
systemctl enable --now auditd
8. CIS Benchmark Check (automatisch)
# OpenSCAP für automatisierte CIS-Prüfung
apt install -y libopenscap8 ssg-debian
oscap xccdf eval --profile xccdf_org.ssgproject.content_profile_cis --results results.xml --report report.html /usr/share/xml/scap/ssg/content/ssg-ubuntu2404-ds.xml
# HTML-Report im Browser öffnen
Checkliste
- System aktuell
- Root-Login deaktiviert
- SSH nur mit Key, Port geändert
- UFW aktiviert mit Minimal-Regeln
- Fail2ban aktiv
- Unattended Upgrades aktiv
- Auditd läuft
FAQ
Sollte ich den SSH-Port ändern?
Ja, reduziert Brute-Force-Versuche in Logs erheblich. Kein absoluter Schutz aber spart Lärm.
Fazit
Diese 8 Schritte härten einen Ubuntu-Server erheblich. Für produktive Server empfehlen wir zusätzlich regelmäßige Vulnerability-Scans.
Linux-Server-Härtung für KMU in Heidelberg, Mannheim und der Rhein-Neckar-Region. IT-Sicherheit anfragen.