使用 SSH 的身份验证顺序

oz1*_*123 25 ssh password public-key

当我通过 ssh 登录时,-v我看到 ssh 正在通过以下方式进行身份验证

debug1: Authentications that can continue: publickey,gssapi-with-mic,password,hostbased
Run Code Online (Sandbox Code Playgroud)

我想改变顺序……知道怎么做吗?

我更大的问题是帐户锁定的用户仍然可以通过公钥登录。我发现我可以将用户添加到一个“ssh-locked”组中,从 ssh 中添加拒绝该组,但我仍然想知道是否有办法告诉 ssh'd: 请在密钥之前检查密码...

Eig*_*ony 36

ssh 服务器决定它允许哪些身份验证选项,ssh 客户端可以配置为决定尝试它们的顺序。

ssh 客户端使用PreferredAuthenticationsssh 配置文件中的选项来确定这一点。

来自man ssh_config在此处在线查看):

PreferredAuthentications
             Specifies the order in which the client should try protocol 2 authentication methods.  This allows a client to prefer
             one method (e.g. keyboard-interactive) over another method (e.g. password).  The default is:

                   gssapi-with-mic,hostbased,publickey,
                   keyboard-interactive,password
Run Code Online (Sandbox Code Playgroud)

我不相信在不使用源代码的情况下,告诉 OpenSSH 服务器更喜欢某个顺序是不可能的——如果你考虑一下,这无论如何都没有意义。


小智 19

添加这个:

PreferredAuthentications keyboard-interactive,password,publickey,hostbased,gssapi-with-mic
Run Code Online (Sandbox Code Playgroud)

...我/etc/ssh/ssh_config帮我解决了这个问题,也节省了很多时间!

您可以通过使用ssh -v user@host命令连接来检查它是否有效,其中-v代表“详细”。

  • 确保您将其添加到正确的文件 `ssh_config` 而不是 `sshd_config`。后者会导致你的 ssh 失败! (2认同)