禁用SSH的密码login与删除所有用户的密码相同吗?

我有一个只有root用户的云服务器。 我只使用RSA密钥进行SSH连接。 为了使它更安全,我想禁用密码function。 我知道这可以通过编辑/etc/ssh/sshd_config文件并将PermitRootLogin yes更改为PermitRootLogin without-password 。 我想知道是否简单地通过passwd -d root删除root密码将是等效的(假设我不创build更多的用户或新用户也删除了他们的密码)。 一种方法是否存在任何安全问题?

使用公钥authentication绕过了其他authentication方法,所以不需要使用PermitRootLogin without-password需要inputPermitRootLogin without-password ,如果有人试图以root身份login而不是强制公开密钥。

要完成你想要的,在sshd中禁用密码authentication,在你的sshd_config使用PasswordAuthentication no

此设置不会影响用户密码存储位置的/etc/shadow的内容。 如果另一个应用程序想通过密码进行身份validation(比如说CUPS),这仍然可以工作。

如果您想禁用此function,则使用上述命令删除用户密码将不起作用。 它允许给定用户的无密码login,这是最初不增加安全性。

发出passwd -l <user>将完成你想要的。 请记住,除了ssh以外的其他应用程序可能会有问题,因为他们希望在默认设置(sudo,su,CUPS等)中进行密码validation。

引用man passwd

 -l, --lock Lock the password of the named account. This option disables a password by changing it to a value which matches no possible encrypted value (it adds a ´!´ at the beginning of the password). Note that this does not disable the account. The user may still be able to login using another authentication token (eg an SSH key). To disable the account, administrators should use usermod --expiredate 1 (this set the account's expire date to Jan 2, 1970). Users with a locked password are not allowed to change their password. 

绝对不是,删除root密码将是一个很大的安全风险,如果你想修改root密码,我build议你为root用户设置一个强大的随机密码。 即使是/etc/shadow

现在,您已将root用户locking为仅用于SSH密钥的SSH访问权限,那么您的下一步就是检查哪些其他用户具有shell访问权限,如果不需要,可以将其删除,并对您可能创build并保留的任何其他用户帐户执行相同的操作仅对root用户进行SSH访问。

如果您select删除任何用户的密码,那么通过将shell设置为/sbin/nologin ,还应该在/etc/passwd删除shell访问权限。

一个不同的方法是禁用所有用户的SSH密码login,并只允许公钥authentication。

ChallengeResponseAuthentication no
PasswordAuthentication no
UsePAM no

还要确保在/etc/ssh/sshd_config允许公钥authentication:

PubkeyAuthentication yes