不同账户的不同ssh认证策略

VeL*_*err 4 ssh configuration user-accounts ubuntu-14.04

我知道我可以为 root 用户(使用PermitRootLogin)禁用带有明文密码的 SSH 身份验证,并为所有其他用户启用它。但是我需要为某些用户列表禁用文本密码(并且只为他们保留公钥身份验证)。对于那些未包含在列表中的人,我还需要启用密码身份验证。

那么,如何为不同的用户调整不同的 SSH 策略呢?在 sshd_config 我发现只有 2 个参数:

PermitRootLogin without-password  # disable text password for root
PasswordAuthentication yes  # enable it for all other users
Run Code Online (Sandbox Code Playgroud)

我想要一些字典式的配置,例如:

user1Auth without-password
user2Auth without-password
user3Auth yes
...
Run Code Online (Sandbox Code Playgroud)

PS 我的操作系统是 Ubuntu 14.04。

EEA*_*EAA 8

您可以使用Match UserorMatch Group指令:

Match Group usergroup
    PasswordAuthentication no
Run Code Online (Sandbox Code Playgroud)

如果不想使用组,可以指定每个用户:

Match User user1,user2
    PasswordAuthentcation yes

Match User user3
    PasswordAuthentication no
Run Code Online (Sandbox Code Playgroud)

我的偏好是从不直接将权限分配给用户(无论系统如何),所以我总是使用组。这也带来了您可以更改组成员身份而无需重新启动 sshd 的好处。

注意。此配置行必须写在/etc/sshd_config.