SSH ist die Eingangstuer des Servers. Sie sichern es mit Schluesseln, ohne Passwort/Root, optional 2FA, und einem Bastion, ueber den Sie zu internen Servern gelangen. Schritt fuer Schritt.
1. ed25519-Schluessel
# pe statia ta: genereaza o cheie ed25519
ssh-keygen -t ed25519 -C 'admin@laptop'
# copiaz-o pe server
ssh-copy-id -i ~/.ssh/id_ed25519.pub admin@server
2. sshd haerten
# /etc/ssh/sshd_config.d/99-hardening.conf
sudo tee /etc/ssh/sshd_config.d/99-hardening.conf >/dev/null <<'EOF'
PermitRootLogin no
PasswordAuthentication no
PubkeyAuthentication yes
KbdInteractiveAuthentication no
AllowUsers admin
X11Forwarding no
MaxAuthTries 3
EOF
sudo sshd -t && sudo systemctl reload ssh
3. 2FA (optional)
# optional: 2FA (TOTP) pt SSH
sudo apt -y install libpam-google-authenticator
google-authenticator # ruleaza ca userul; scaneaza QR in app
# apoi activeaza in PAM + sshd (AuthenticationMethods publickey,keyboard-interactive)
4. Bastion / Jump-Host
# bastion / jump host — te conectezi la serverele interne PRIN bastion
# ~/.ssh/config pe statie:
Host bastion
HostName bastion.example.com
User admin
Host intern-*
ProxyJump bastion
User admin
# apoi: ssh intern-db (trece automat prin bastion)
5. Anti-Brute-Force
# protectie brute-force (fail2ban SAU crowdsec)
sudo apt -y install fail2ban
sudo systemctl enable --now fail2ban
sudo fail2ban-client status sshd
6. Pruefen
sudo sshd -T | grep -Ei 'permitroot|passwordauth|pubkey|allowusers'
ssh -J bastion admin@intern-db # test bastion
Fazit
Sie haben nun gehaertetes SSH: nur Schluessel, kein Root, optional 2FA, Bastion-Zugriff und Brute-Force-Schutz. HINWEIS: Lassen Sie beim Testen eine Sitzung offen, um sich nicht auszusperren. Wir konfigurieren es fuer Sie.