In one of my previous posts, I've mentioned locking down SSHD in terms of Algorithms, MACs, and Ciphers for the connection. This config is intended to work on larger fleets of servers and I'll not go into obscurity, meaning I will not change the SSH Port to something else.
However, these are probably the most important settings to change for a larger fleet of servers.
Protocol Versions
Let's start with the first setting, pinning the protocol to version 2:
[archy@ansible01 ~]$ sudo vim /etc/ssh/sshd_config
Protocol 2
Ciphers, Algorithms, and MACs
At the time of writing this (11/2020), the first algorithms tend to be the most secure, and the second mentioned ones tend to be focused on compatibility. If you are using an updated ssh-client, it should always pick the first.
[archy@ansible01 ~]$ sudo vim /etc/ssh/sshd_config
KexAlgorithms curve25519-sha256@libssh.org,diffie-hellman-group-exchange-sha256
Ciphers chacha20-poly1305@openssh.com,aes256-ctr
MACs hmac-sha2-512-etm@openssh.com,hmac-sha2-512
Root Logins
Do not allow root-logins using passwords. If you have to log in using the root user, only allow ssh-key authentication. This involves setting up keys on the client and copying it to the ~/.ssh/authorized_keys file on the destination server. First up, create the ssh-key on the client:
[0:36:11 archy@stealth-falcon ~]$ ssh-keygen -t ed25519 -b 521
NOTE: 521 is not a typo, see the ssh-keygen manual for more info. Next, copy the key to the server and modify the sshd_config:
[0:36:18 archy@stealth-falcon ~]$ ssh archy@ansible01.archyslife.lan
[archy@ansible01 ~]$ sudo su - -c 'echo "ssh_key_data" >> /root/.ssh/authorized_keys
[0:36:26 archy@stealth-falcon ~]$ ssh root@ansible01.archyslife.lan
[root@ansible01 ~]$ vim /etc/ssh/sshd_config
PermitRootLogin without-password
This way, brute-force attacks will not be working with passwords. In order to log in as the 'root' user, you'll have to have an authorized ssh-key.NOTE: Never expose the ssh-port to the public internet, this will minimize the attack surface further.
User Logins
For user logins, there are 3 options, passwords, ssh-keys, and gssapi (Kerberos).
Preferably, do not allow password-logins at all on your systems and have your users either login using gssapi or ssh-keys. For gssapi to work, you should have your servers joined to an identity management solution such as FreeIPA. Now to the options that should be adjusted:
[archy@ansible01 ~]$ sudo vim /etc/ssh/sshd_config
PermitEmptyPasswords no
PasswordAuthentication no
ChallengeResponseAuthentication no
If you decide to use gssapi, the enrollment of the freeipa-client will automatically configure sshd to utilize it if available unless you opt-out of it.
Feel free to comment and / or suggest a topic.
Comments
Post a Comment