OpenSSH 服务器报告冲突的身份验证方法

OpenSSH 服务器报告冲突的身份验证方法

我们在使用 SSH 密码连接服务器时遇到了问题。奇怪的是,我看到了相互矛盾的身份验证方法:

$ ssh -v [email protected] -o PreferredAuthentications=password
OpenSSH_7.9p1, OpenSSL 1.1.1a  20 Nov 2018
debug1: Connecting to example.com [1.2.3.4] port 22.
debug1: Connection established.
debug1: Local version string SSH-2.0-OpenSSH_7.9
debug1: Remote protocol version 2.0, remote software version OpenSSH_7.4
debug1: match: OpenSSH_7.4 pat OpenSSH_7.0*,OpenSSH_7.1*,OpenSSH_7.2*,OpenSSH_7.3*,OpenSSH_7.4*,OpenSSH_7.5*,OpenSSH_7.6*,OpenSSH_7.7* compat 0x04000002
[...]
debug1: Authentications that can continue: publickey,password <<< HERE
debug1: Next authentication method: password
[email protected]'s password:
debug1: Authentications that can continue: publickey,password
Permission denied, please try again.
[email protected]'s password:
debug1: Authentications that can continue: publickey,password
Permission denied, please try again.
[email protected]'s password:
debug1: Authentications that can continue: publickey
debug1: No more authentication methods to try.
[email protected]: Permission denied (publickey). <<< HERE

我的理解是,标记的两行应该显示匹配的身份验证方法,因此

debug1: Authentications that can continue: publickey
[...]
[email protected]: Permission denied (publickey).

或者

debug1: Authentications that can continue: publickey,password
[...]
[email protected]: Permission denied (publickey,password).

例如,查看具有匹配身份验证方法的其他日志这里这里, 和这里

这是表明存在问题的迹象,还是无害的变化?


编辑:

1:我不是在寻求有关如何在 sshd_config 上设置身份验证方法的帮助,这已经完成了。

2:这个应该不是输入错误密码导致的,因为我刚刚在个人服务器上测试过,方法还是符合的:

$ ssh -v [email protected] -o PreferredAuthentications=password
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug1: Authentications that can continue: publickey,password <<< HERE
debug1: Next authentication method: password
[email protected]'s password:
debug1: Authentications that can continue: publickey,password
Permission denied, please try again.
[email protected]'s password:
debug1: Authentications that can continue: publickey,password
Permission denied, please try again.
[email protected]'s password:
debug1: Authentications that can continue: publickey,password
debug1: No more authentication methods to try.
[email protected]: Permission denied (publickey,password). <<< HERE

3:这也不是一个错误的用户名,或者标志-o PreferredAuthentications=password,我的个人服务器仍然会对Permission denied (publickey,password).这些情况做出回复。

答案1

我认为您在调试中发生的情况是,在您允许的身份验证尝试失败后,服务器或客户端会告诉您不再允许输入密码,并且客户端必须尝试使用​​公钥。

因此,您的用户名或密码输入不正确(或者用户无权使用 SSH)。此外,它最后也不喜欢您的公钥。如果此问题仍然存在,并且您认为您输入的凭据正确,您可以:

  1. 已达到身份验证请求的限制。
  2. 您的服务器上的权限配置错误。请参阅 Nicolas Carey 的在这里回答

要解决第一个问题,您需要在服务器上重新启动 sshd 进程并更正 .ssh 目录权限(特别是 authorized_keys)。

答案2

我们有 6 种已知的 ssh 方法。

**Password authentication:** Client will ask you to enter a password, will encrypt it and use it to authenticate itself to a server.
**Public key authentication:** Each client uses a key pair to authenticate itself to a server. Server should find the key in the list of allowed keys.
**Host based authentication:** This method is similar to public key authentication, but client should not only use correct key, but also must connect from correct host.
**Keyboard authentication:** Server will use client to present zero or more prompts to client PC operator and request answers from operator.
**Challenge Response Authentication:** Used to configure keyboard authentication. You should use specific backend send the challenges and check the responses.
**GSSAPI Authentication:** GSSAPI is a IETF standard for strong encrypted authentication. OpenSSH uses GSSAPI and kerberos 5 code to authenticate clients.

现在在 sshd_config 配置中决定哪个是可以接受的。

$ egrep ^'PasswordAuthentication|PubkeyAuthentication' /etc/ssh/sshd_config
PasswordAuthentication yes
PubkeyAuthentication yes

现在下面的几行显示了服务器可以接受的内容。

debug1: Authentications that can continue: publickey,password

此行显示了这些行之前接受的内容。

debug1: Next authentication method: publickey #After this section.
debug1: Authentication succeeded (publickey,password)

因此,在您的情况下,我猜测支持的方法是,publickey and password但是您传递PreferredAuthentications=password它时首先尝试并失败,之后作为公钥应用的后备也是一个启用的选项。

所以我猜如果不添加PreferredAuthentications选项,您可能会看到预期的结果。您可能会因为回退而看到意外的调试输出。

答案3

我并不恳求这样做,因为我想鼓励用户通过 SSH 使用公钥——您可能应该对此进行更多研究。

但是,如果您只想通过 ssh 使用密码方法,请在尝试连接的服务器上执行以下操作:

  1. 须藤纳米/etc/ssh/sshd_config

  2. 搜索PubkeyAuthentication并将选项设置为yesno

PubkeyAuthentication no

如果尚不存在此行,则添加此行;如果存在此行,则删除行首的 #。将其设置为 yes 以允许公钥身份验证方法,设置为 no 以禁止。

在禁用公钥身份验证方法之前,请确保已启用其他身份验证方法(例如密码),因为您可能会完全失去对服务器的远程访问权限。

  1. 重新加载或重新启动 SSH 服务器服务以使更改生效。

sudo systemctl restart sshd

相关内容