在Linux(Debian Squeeze)上,我想对某些用户(选定的组或除root以外的所有用户)使用密码禁用SSH登录。但是我不想禁用使用证书的登录。
edit:非常感谢您的详细回答!由于某些原因,这在我的服务器上不起作用:
Match User !root
PasswordAuthentication no
...但是很容易被替换
PasswordAuthentication no
Match User root
PasswordAuthentication yes
在sshd_config
中尝试Match
:
Match User user1,user2,user3,user4
PasswordAuthentication no
或按组:
Match Group users
PasswordAuthentication no
或者,如评论中所述,通过否定:
Match User !root
PasswordAuthentication no
请注意,匹配是有效的 “直到另一根Match行或文件末尾。” (缩进并不重要)
Match
in sshd_config
效果很好。您应该使用Match all
结束匹配块(如果您使用的是openssh 6.5p1或更高版本)。例:
PasswordAuthentication no
Match User root
PasswordAuthentication yes
Match all
有几种方法可以执行此操作-首先,可以使用不同的配置在不同的端口上方便地运行第二个sshd守护程序-这有点麻烦,但是通过chroot工作,它应该可以正常工作。
另外,您可以允许密码验证,但可以锁定一个用户以外的所有用户的密码。密码已锁定的用户仍然可以使用公共密钥进行身份验证。