如何禁用某些用户的SSH密码login?

在Linux上(Debian Squeeze)我想禁用SSHlogin使用密码给一些用户(选定的组或除root以外的所有用户)。 但我不想禁用login使用他们的证书。

编辑:非常感谢您的详细解答! 出于某种原因,这不适用于我的服务器:

Match User !root PasswordAuthentication no 

…但可以很容易地被replace

 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 

    请注意,匹配是有效的“直到另一个匹配行或文件的结尾”。 (缩进不显着)

    sshd_config Match效果很好。 如果您使用openssh 6.5p1或更高版本,则应该使用Match all来结束匹配块。 例:

     PasswordAuthentication no Match User root PasswordAuthentication yes Match all 

    有几种方法可以做到这一点 – 首先,您可以在不同的端口上以不同的configuration运行第二个sshd守护进程 – 这有点破解,但是对于一些chroot工作,它应该可以正常工作。

    此外,您可以允许密码validation,但locking除一个用户以外的所有密码。 locking密码的用户仍然可以使用公钥进行身份validation。

    你可以简单地去/ etc / ssh / sshd_config文件并添加一行允许 – > AllowUsers user1拒绝—> DenyUsers user2

    我们可以使用位于/ etc文件夹中的hosts.allow或hosts.deny文件来允许/拒绝特定主机集的login