我正在尝试创建一个新用户并在命令行中直接关联密码(测试通过),而不会出现提示。我在 Debian 上收到此错误:
Enter new UNIX password: Retype new UNIX password: passwd: Authentication token manipulation error
passwd: password unchanged
Use of uninitialized value $answer in chop at /usr/sbin/adduser line 556.
Try again? [y/N] Use of uninitialized value $answer in pattern match (m//) at /usr/sbin/adduser line 557.
我这样做:
adduser --gecos "" plmadmin
echo testpass:testpass | chpasswd
adduser plmadmin sudo
答案1
您可以使用这个小脚本并为其提供 2 个参数:
#!/usr/bin/env bash
if (($# < 2));
then
printf 'Please provide the username and password\n'; exit 1
else
adduser "$1"
printf "$1:%s" "$2" | chpasswd
fi
1)将脚本保存在文件中,例如addUsers(无扩展名)
2) chmod u+x 添加用户
3) ./addUsers 用户名 密码
答案2
--disabled-password
Like --disabled-login, but logins are still possible (for example using SSH RSA keys) but not using password authentication.
-u, --unlock
Unlock the password of the named account. This option re-enables a password by changing the password back to its previous value (to the value before using the -l option).
adduser --disabled-password --gecos "" plmadmin
echo -e "testpass\ntestpass\n" | passwd plmadmin
passwd -u plmadmin
- 禁用密码禁用密码登录,并且系统不会提示您输入密码。
- 密码将更改为您设置的密码。
- 帐户的密码再次启用。