如何完全禁用密码 ssh 登录?

如何完全禁用密码 ssh 登录?

我正在设置一个运行 raspbian 操作系统的树莓派 3,它将在启用 ssh 的情况下不断连接到 wifi,因此安全性是必须的。我已成功通过公钥-私钥对启用登录,并试图使其成为通过 ssh 访问 pi 的唯一方法。

我查看了有关此主题的一些主题,并在 sshd_config 文件中搜索了任何带有密码登录的内容(PasswordAuthentication、PermitRootLogin、KerberosAuthentication、UsePAM 等)以将它们全部关闭,但无济于事。一旦使用公钥登录失败,它会立即提示输入密码。

我已经重新启动了 sshd,甚至重新启动了 pi 几次,但没有任何变化。

我并不太绝望,因为密码非常强大,但如果可以使用密码登录,那么使用公钥登录似乎是一种浪费。

答案1

就我而言,我编辑/etc/ssh/sshd_config并取消注释了该行PasswordAuthentication no,在我的情况下,现在如果客户端未发送密钥或未经授权的密钥,服务器将关闭连接。只要确保该行没有被注释,#PasswordAuthentication no#是注释并且被忽略,并且由于默认是yes它不会工作。

答案2

人 sshd:

 AuthenticationMethods

         For example, an argument of “publickey,password
         publickey,keyboard-interactive” would require the user to com‐
         plete public key authentication, followed by either password or
         keyboard interactive authentication.  Only methods that are next
         in one or more lists are offered at each stage, so for this exam‐
         ple, it would not be possible to attempt password or keyboard-
         interactive authentication before public key.

因此,选择您唯一喜欢的一个:

AuthenticationMethods publickey

您看到的密码请求并不是要求 pam 密码,而是要求密码保护的公钥 - 您还没有尝试过。

相关内容