大网数据广告活动
服务器运维问答

OpenSSH: Different Authentication Methods

· 52CE 我爱测

I have the need of having users logging in to a CentOS system with different authentication methods. Some using password and others using public key. I followed the methods mentioned here: How can I setup OpenSSH per-user authent…

问题原文

原帖链接 · Prabhu · CC BY-SA 3.0

I have the need of having users logging in to a CentOS system with different authentication methods. Some using password and others using public key.

I followed the methods mentioned here: How can I setup OpenSSH per-user authentication methods?

However, I am not successful in having successful password based login.

In the sshd_config file, I have:

AuthenticationMethods keyboard-interactive,publickey
PasswordAuthentication no

Match User newton
    PasswordAuthentication yes
Match all

Update: I see that the issue is only when I have 2FA enabled with google authentication and I have the line:

AuthenticationMethods keyboard-interactive,publickey

Though for the user newton, I have set password authentication I see the following error:

[root@localhost]# ssh [email omitted]
Permission denied (publickey).

Any suggestions are appreciated.

已采纳解答

原帖链接 · Jakuje · CC BY-SA 3.0

Although @Tolsadus answer probably points to the correct solution, it does not answer the question clearly.

In short, manual page for ssh_config is a good start to understand how the config parser in ssh works (the same rules apply for sshd_config):

For each parameter, the first obtained value will be used

This means that your example will set PasswordAuthentication to no for all users and for newton user will not overwrite it (because it is already set). To work it around, you should set the default values in the Match block. This will have the expected effect on newton user:

Match User newton
    PasswordAuthentication yes
Match all
    PasswordAuthentication no

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2017-02-17)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 3.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。