OpenSSH:不同的身份验证方法

Pra*_*bhu 5 linux ssh

我需要让用户使用不同的身份验证方法登录 CentOS 系统。有些使用密码,有些使用公钥。

我遵循了这里提到的方法: How can I setup OpenSSH per-user authentication methods?

但是,我没有成功基于密码登录。

在 sshd_config 文件中,我有:

AuthenticationMethods keyboard-interactive,publickey
PasswordAuthentication no

Match User newton
    PasswordAuthentication yes
Match all
Run Code Online (Sandbox Code Playgroud)

更新:我发现问题仅在我通过谷歌身份验证启用了 2FA 并且我有以下线路时:

AuthenticationMethods keyboard-interactive,publickey
Run Code Online (Sandbox Code Playgroud)

虽然对于用户 newton,我已经设置了密码身份验证,但我看到以下错误:

[root@localhost]# ssh newton@50.39.213.152
Permission denied (publickey).
Run Code Online (Sandbox Code Playgroud)

任何建议表示赞赏。

Jak*_*uje 6

尽管@Tolsadus 的回答可能指向了正确的解决方案,但它并没有清楚地回答问题。

简而言之,手册页ssh_config是了解 ssh 中配置解析器如何工作的良好开端(同样的规则适用于sshd_config):

对于每个参数,将使用第一个获得的值

这意味着您的示例将为所有用户设置PasswordAuthenticationno,并且newton用户不会覆盖它(因为它已经设置)。要解决这个问题,您应该在Match块中设置默认值。这将对newton用户产生预期的影响:

Match User newton
    PasswordAuthentication yes
Match all
    PasswordAuthentication no
Run Code Online (Sandbox Code Playgroud)