04. Hardened OpenSSH server

Cześć, Jakiś czas temu pisałem Wam o ciekawym artykule na stronie ZaufanaTrzeciaStrona. Od tamtej pory minęło dużo czasu wyszły nowe wersje Debian 10 i 11 ale również narzędzie przestało być wspierane i ktoś inny przejął projekt. Dlatego ponownie dla Was postanowiłem pokombinować jak zrobić aby nasz serwer SSH był super bezpieczny według narzędzia, które dostarczyli ( nie oznacza to, że poniższy post łata wszystkie słabe punkty OpenSSH ).
Pod lupę wziąłem dystrybucje Debian:
Debian 8.0 ( Jessie )
Debian 9.0 ( Stretch )
Debian 10.0 ( Buster )
Debian 11.0 ( Bullseye )

Po przeczytaniu manuala i paru próbach na VM niestety muszę stwierdzić, że w związku z użytą stara wersją OpenSSH w Debian 8 ( OpenSSH_6.7p1 ) nie ma możliwości ustawienia HostKeyAlgorithms co za tym idzie nie ma możliwości osiągnięcia idealnego wyniku za pomocą tego narzędzia.

W skrócie:
Debian 8.x dopisujemy na końcu pliku /etc/ssh/sshd_config :
KexAlgorithms curve25519-sha256@libssh.org
Ciphers chacha20-poly1305@openssh.com,aes128-ctr,aes192-ctr,aes256-ctr,aes128-gcm@openssh.com,aes256-gcm@openssh.com
MACs hmac-sha2-512-etm@openssh.com,hmac-sha2-256-etm@openssh.com,umac-128-etm@openssh.com

Debian 9.x dopisujemy na końcu pliku /etc/ssh/sshd_config :
KexAlgorithms curve25519-sha256,curve25519-sha256@libssh.org,diffie-hellman-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 ssh-ed25519,ssh-ed25519-cert-v01@openssh.com

Debian 10.x dopisujemy na końcu pliku /etc/ssh/sshd_config :
KexAlgorithms curve25519-sha256,curve25519-sha256@libssh.org,diffie-hellman-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 ssh-ed25519,ssh-ed25519-cert-v01@openssh.com,rsa-sha2-256,rsa-sha2-512,rsa-sha2-256-cert-v01@openssh.com,rsa-sha2-512-cert-v01@openssh.com

Debian 11.x dopisujemy na końcu pliku /etc/ssh/sshd_config :
KexAlgorithms curve25519-sha256,curve25519-sha256@libssh.org,diffie-hellman-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 ssh-ed25519,ssh-ed25519-cert-v01@openssh.com,sk-ssh-ed25519@openssh.com,sk-ssh-ed25519-cert-v01@openssh.com,rsa-sha2-256,rsa-sha2-512,rsa-sha2-256-cert-v01@openssh.com,rsa-sha2-512-cert-v01@openssh.com

Pamiętajcie aby po zmianie konfiguracji wpierw wydać polecenie:
sshd -t
Jeśli wyskoczy Wam błąd, że brakuje jakiegoś pliku to:
ssh-keygen -q -N „” -t rsa -b 4096 -f /etc/ssh/ssh_host_rsa_key
ssh-keygen -q -N „” -t ecdsa -f /etc/ssh/ssh_host_ecdsa_key