SSH-Server Hardening

Aus Xinux Wiki
Zur Navigation springen Zur Suche springen

Passwortauthentifizierung abschalten

  • vim /etc/ssh/sshd_config
...
PubkeyAuthentication yes
AuthorizedKeysFile .ssh/authorized_keys
...
PasswordAuthentication no
PermitEmptyPasswords no
...
UsePAM no
...
  • systemctl restart sshd
  • Nun werden nur noch Benutzer mit dem entsprechenden privaten Schlüssel unter ~/.ssh/authorized_keys angemeldet

SSH Server Optionen einschränken

  • Die AllowTcpForwarding-Option kann ausgenutzt werden, um Firewalls zu umgehen
  • Die X11Forwarding-Option kann benutzt werden, um graphische Programme über SSH zu tunneln
  • an sich stellt diese Option kein Sicherheitsrisiko dar
  • jedoch wird sie selten benutzt und ist selbst dann sehr langsam
  • vim /etc/ssh/sshd_config
...
AllowTcpForwarding no
#GatewayPorts no
X11Forwarding no
...

veraltete Cipher-Suites entfernen

  • vim /etc/ssh/sshd_config
...
KexAlgorithms sntrup761x25519-sha512@openssh.com,curve25519-sha256,curve25519-sha256@libssh.org,gss-curve25519-sha256-,diffie-hellman-group16-sha512,gss-group16-sha512-,diffie-hellman-group18-sha512,diffie-hellman-group-exchange-sha256

Ciphers chacha20-poly1305@openssh.com,aes256-gcm@openssh.com,aes128-gcm@openssh.com,aes256-ctr,aes192-ctr,aes128-ctr

MACs hmac-sha2-256-etm@openssh.com,hmac-sha2-512-etm@openssh.com,umac-128-etm@openssh.com

HostKeyAlgorithms sk-ssh-ed25519-cert-v01@openssh.com,ssh-ed25519-cert-v01@openssh.com,rsa-sha2-512-cert-v01@openssh.com,rsa-sha2-256-cert-v01@openssh.com,sk-ssh-ed25519@openssh.com,ssh-ed25519,rsa-sha2-512,rsa-sha2-256

RequiredRSASize 3072

HostbasedAcceptedAlgorithms sk-ssh-ed25519-cert-v01@openssh.com,ssh-ed25519-cert-v01@openssh.com,sk-ssh-ed25519@openssh.com,ssh-ed25519,rsa-sha2-512-cert-v01@openssh.com,rsa-sha2-512,rsa-sha2-256-cert-v01@openssh.com,rsa-sha2-256

PubkeyAcceptedAlgorithms sk-ssh-ed25519-cert-v01@openssh.com,ssh-ed25519-cert-v01@openssh.com,sk-ssh-ed25519@openssh.com,ssh-ed25519,rsa-sha2-512-cert-v01@openssh.com,rsa-sha2-512,rsa-sha2-256-cert-v01@openssh.com,rsa-sha2-256
...

Überprüfen mit ssh-audit

  • apt install ssh-audit
  • ssh-audit ip.des.gehärteten.hosts

Links