Skip to content

Server härten

Reihenfolge beim ersten Mal: SSH härten → Updates → Firewall → Fail2ban → Backups einrichten & testen → dann erst Dienste draufpacken.

Diese Seite ist die Kurzfassung. Für ausführliche Schritt-für-Schritt-Walkthroughs siehe:


  • SSH-Keys only, root-Login aus, Passwort-Auth aus
  • Non-root User mit sudo anlegen
  • Optional: Port ändern (nur Security through Obscurity)

Befehle:

Terminal window
# Neuen User anlegen
adduser deploy
usermod -aG sudo deploy
# SSH-Config härten
sudo nano /etc/ssh/sshd_config
# PasswordAuthentication no
# PermitRootLogin no
# PermitEmptyPasswords no
# X11Forwarding no
sudo systemctl restart sshd
Terminal window
apt update && apt full-upgrade
apt install unattended-upgrades
dpkg-reconfigure -plow unattended-upgrades # Security-Updates automatisch

Automatische Reboots für Kernel-Updates (Debian 12+/Ubuntu 22.04+):

Terminal window
apt install unattended-upgrades
# In /etc/apt/apt.conf.d/50unattended-upgrades:
# Unattended-Upgrade::Automatic-Reboot "true";
Terminal window
apt install ufw
ufw default deny incoming
ufw default allow outgoing
ufw allow 22/tcp
ufw allow 80,443/tcp
ufw enable
ufw status verbose
Terminal window
apt install fail2ban
systemctl enable --now fail2ban
# Status & Bans anschauen
fail2ban-client status sshd
fail2ban-client status sshd | grep "Banned IP list"
Terminal window
timedatectl set-timezone Europe/Berlin
apt install systemd-timesyncd && systemctl enable --now systemd-timesyncd
timedatectl status
  • Cron + restic/borg → S3 oder Hetzner Storage Box
  • Test: Restore üben, nicht nur Backup laufen lassen
Terminal window
apt install restic
restic -r sftp:backup@backup.example.com:/srv/backups init

Ausführlich: Server Backups


Bonus-Härtung (nicht Pflicht, aber sinnvoll)

Section titled “Bonus-Härtung (nicht Pflicht, aber sinnvoll)”
Terminal window
# Auf dem Client
ssh-keygen -t ed25519 -a 100 -C "deploy@workstation"
ssh-copy-id -i ~/.ssh/id_ed25519.pub deploy@server
# Auf dem Server: alte RSA-Keys der authorized_keys löschen

SSH: 2-Faktor mit TOTP (Google Authenticator)

Section titled “SSH: 2-Faktor mit TOTP (Google Authenticator)”
Terminal window
apt install libpam-google-authenticator
google-authenticator
# Scannen mit Authenticator-App, Recovery-Codes notieren!
# /etc/ssh/sshd_config:
# ChallengeResponseAuthentication yes
# AuthenticationMethods publickey,keyboard-interactive
# UsePAM yes
sudo systemctl restart sshd

Wenn der Server nur aus bekannten Netzen erreichbar sein muss:

/etc/wireguard/wg0.conf
apt install wireguard
# [Interface]
# Address = 10.0.0.1/24
# ListenPort = 51820
# PrivateKey = <server-key>
# [Peer]
# PublicKey = <client-key>
# AllowedIPs = 10.0.0.2/32
systemctl enable --now wg-quick@wg0
# ufw: SSH-Port dichtmachen, nur WireGuard erlauben
ufw delete allow 22/tcp
ufw allow 51820/udp
/etc/sysctl.d/99-hardening.conf
# IP-Spoofing-Schutz
net.ipv4.conf.all.rp_filter = 1
net.ipv4.conf.default.rp_filter = 1
# ICMP-Redirects ignorieren
net.ipv4.conf.all.accept_redirects = 0
net.ipv4.conf.default.accept_redirects = 0
net.ipv4.conf.all.secure_redirects = 0
net.ipv6.conf.all.accept_redirects = 0
# Source-Routing deaktivieren
net.ipv4.conf.all.accept_source_route = 0
net.ipv6.conf.all.accept_source_route = 0
# SYN-Flood-Schutz
net.ipv4.tcp_syncookies = 1
sudo sysctl --system

Rechtlicher Hinweis: Unbefugte Zugriffe werden strafrechtlich verfolgt.

Terminal window
# /etc/issue.net (vor SSH-Login)
echo "Unauthorized access prohibited. All activities are logged." | sudo tee /etc/issue.net
# /etc/motd (nach Login)
echo "Welcome. This system is for authorized users only." | sudo tee /etc/motd
Terminal window
apt install auditd audispd-plugins
systemctl enable --now auditd
# Wichtige Regeln in /etc/audit/rules.d/audit.rules:
# -w /etc/passwd -p wa -k identity
# -w /etc/shadow -p wa -k identity
# -w /etc/sudoers -p wa -k sudoers
# -w /var/log/auth.log -p wa -k auth_log
auditctl -l # aktive Regeln
ausearch -k identity # nach "identity"-Events suchen
Terminal window
apt install rkhunter chkrootkit clamav-daemon
systemctl enable --now clamav-daemon
# Wöchentlicher Scan via Cron:
# 0 3 * * 0 /usr/bin/rkhunter --check --cronjob --report-warnings-only

Checkliste “Server ist produktionsreif”

Section titled “Checkliste “Server ist produktionsreif””
  • SSH nur mit Pubkey-Login, root-Login aus
  • Non-root User mit sudo, eigener SSH-Key
  • ufw aktiv: nur 22/80/443 offen (oder nur WireGuard)
  • fail2ban läuft, sshd-Jail aktiv
  • unattended-upgrades aktiv
  • Zeitsync via systemd-timesyncd
  • Sysctl-Härtung geladen
  • restic-Repo initialisiert + erster Backup + Restore getestet
  • auditd oder mindestens auth.log-Monitoring
  • Login-Banner gesetzt
  • Snapshot/Konfiguration der Firewall ist dokumentiert

Wenn alle Häkchen gesetzt sind: jetzt erst Dienste deployen.