Aus Free Software
Version vom 20. Juli 2019, 15:15 Uhr von Mati (Diskussion | Beiträge)
(Unterschied) ← Nächstältere Version | Aktuelle Version (Unterschied) | Nächstjüngere Version → (Unterschied)
Zur Navigation springen Zur Suche springen


based on (with a stripped down list of Ciphers and MACs)

Server configuration

Remove all HostKey directives in /etc/ssh/sshd_config, then append at the bottom:

# SSH hardening, see

# Disable SSHv1
Protocol 2

# Only allow Public Key Authentication
PubkeyAuthentication yes
PasswordAuthentication no
ChallengeResponseAuthentication no

# Only allow users in the "users" group (no system users!).
# NOTE: See /etc/adduser.conf (EXTRA_GROUPS and ADD_EXTRA_GROUPS) to 
# automatically add new non-system users to a group.
AllowGroups users
# Don't forget to remove HostKey directives above
HostKey /etc/ssh/ssh_host_rsa_key
HostKey /etc/ssh/ssh_host_ed25519_key

... and execute:

cd /etc/ssh/
rm ssh_host_*
ssh-keygen -t rsa -b 4096 -f ssh_host_rsa_key -N ""
ssh-keygen -t ed25519 -f ssh_host_ed25519_key -N ""
restart server

When restarting, current session is not affected, make sure you keep it open, in case you've done something wrong:

systemctl restart sshd

Client configuration

On top of your ~/.ssh/config, add:

Host *

Note that we add diffie-hellman-group-exchange-sha256 in comparison to the server config - this is for comparability with Ubuntu 12.04 (remove it if you don't care).

If possible, you can also regenerate your own SSH keys:

ssh-keygen -t ed25519 -o -a 100
ssh-keygen -t rsa -b 4096 -o -a 100

WARNING: This overwrites your old keys if you're not careful. If you don't add a new key to your servers before removing the old ones, you're locked out.