如何将 /etc/shadow 中的密码更改为 *

如何将 /etc/shadow 中的密码更改为 *

查看 /etc/shadow,我发现系统帐户的密码字段中有一个 * 字符,因此无法使用密码以这些帐户身份登录。

我有一个自己创建的用户帐户,现在我想在 /etc/shadow 中使用 * 作为密码。

我找不到任何可以执行此操作的命令行工具,我所能做的就是手动编辑阴影。

有这样的命令行工具吗?

答案1

为了使使用密码登录帐户变得不可能,只需将影子密码条目设为无效哈希即可 - 实现此目的的常用方法是添加一个!字符,您可以使用命令的-l或选项来执行此操作。来自:--lockpasswdman 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 (e.g. 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.

如果你真的但是,如果你想用单个字符替换散列密码*,你可以使用以下命令进行操作usermod

sudo usermod -p '*' someuser

也可以看看:

相关内容