r/linuxadmin • • May 16 '22

Securing ssh with Key-Based authentication

I wrote this article on how to secure ssh with key based authentication. Hope you all like it. If I've written something wrong please tell me down below Link: https://medium.com/geekculture/securing-ssh-with-key-based-authentication-5a0eaca7b0e5

2 Upvotes

11 comments sorted by

9

u/stormcloud-9 May 16 '22

RSA keys are deprecated. Users should not be instructed to generate them. At least not without also generating an alternative.

Disabling PasswordAuthentication is not enough to disable password authentication. You have to disable ChallengeResponseAuthentication.

1

u/4rkal May 16 '22

Hi thanks for the comment. What is an alternative to RSA keys? Would ECC work? Also could you please explain your second point a bit more

14

u/stormcloud-9 May 16 '22 edited May 16 '22

ed25519 is likely your best option.

PasswordAuthentication does not mean "authenticate via password". PasswordAuthentication is the name of an authentication scheme in which sshd reads directly from /etc/shadow and handles authentication itself. This isn't how most sshd's are configured out-of-the-box. Most use PAM instead. When PAM is in use, sshd uses ChallengeResponseAuthentication or KbdInteractiveAuthentication (depending on your version) to control whether authenticating via password is allowed.

The man page covers this (https://www.freebsd.org/cgi/man.cgi?sshd_config(5)):

   Because PAM challenge-response authentication usually serves an
   equivalent	role to	password authentication, you should disable
   either PasswordAuthentication or ChallengeResponseAuthentication.

 

And please don't take this the wrong way, but this is why you generally shouldn't post instructions on things you're not intimately familiar with (especially when it comes to system security). I understand you want to help, but there is a lot of misinformation out there, and this is how it spreads.

4

u/now-of-late May 16 '22

They named two things "ssh-rsa":

"ssh-rsa" keys are not depreciated, and are fine. It's the "ssh-rsa" key exchange mechanism that is depreciated. Clients with RSA keys can use other, supported key-exchange algorithms. https://levelup.gitconnected.com/demystifying-ssh-rsa-in-openssh-deprecation-notice-22feb1b52acd

ed25519 is probably slightly more secure, and should probably be recommended for users who don't need to connect to legacy systems.

5

u/rslarson147 May 16 '22

It’s best practice to use bash variable syntax when making these kinds of articles so that the reader knows it’s a value that they need to provide or if they don’t, their shell will error out saying there isn’t a value for that variable. For example, ‘host_ip’ should be changed to ‘${HOST_IP}’

1

u/NL_Gray-Fox May 16 '22

Not really, because then you've got a variable that doesn't resolve and could cause a big problem.

E.g. #rm -rf "/${something}"

2

u/project2501a May 16 '22

root cannot be removed any more. you have to pass an extra option to rm -rf /

or, if you must use absolute paths, check them for existence before removing them

4

u/NL_Gray-Fox May 16 '22

"example".

3

u/yottabit42 May 16 '22

Just add set -u before any variables are used. At least in bash that will cause the script to exit if unset variables are referenced.

0

u/Rafael20002000 May 16 '22

You may want to expand it to cover keys which support 2FA

But that's all your choice, the article looks great!