我正在尝试批量创建多个用户帐户,并且我拥有 /etc/passwd 的完全权限
然而,这个命令
sudo echo "vv1:myUltraSecretPassword" | newusers
Run Code Online (Sandbox Code Playgroud)
总是返回这个错误
newusers: Permission denied.
newusers: cannot lock /etc/passwd; try again later.
Run Code Online (Sandbox Code Playgroud)
我已经在https://superuser.com/q/296373/1100842帖子中尝试了所有解决方案
例如删除锁定文件
ubuntu@VM-0-17-ubuntu:~$ sudo rm /etc/passwd.lock
rm: cannot remove '/etc/passwd.lock': No such file or directory
ubuntu@VM-0-17-ubuntu:~$ sudo rm /etc/shadow.lock
rm: cannot remove '/etc/shadow.lock': No such file or directory
ubuntu@VM-0-17-ubuntu:~$ sudo rm /etc/group.lock
rm: cannot remove '/etc/group.lock': No such file or directory
ubuntu@VM-0-17-ubuntu:~$ sudo rm /etc/gshadow.lock
rm: cannot remove '/etc/gshadow.lock': No such file or directory
Run Code Online (Sandbox Code Playgroud)
并安装重新安装
sudo mount -o remount,rw /
Run Code Online (Sandbox Code Playgroud)
Ter*_*nce 10
首先,sudo
需要newusers
命令而不是echo
命令。您收到无法锁定的消息,因为sudo
它没有从echo
命令传递到newusers
命令。所以,你需要移动sudo
到后|
前newusers
。
echo
命令中密码行的布局缺少字段,因此如果您sudo
的位置正确,您可能会看到如下错误消息
newusers: line 1: invalid line
newusers: error detected, changes ignored
Run Code Online (Sandbox Code Playgroud)
从手册页newusers
我们可以看到它显示了所有必需的字段。
DESCRIPTION
The newusers command reads a file (or the standard input by default)
and uses this information to update a set of existing users or to
create new users. Each line is in the same format as the standard
password file (see passwd(5)) with the exceptions explained below:
pw_name:pw_passwd:pw_uid:pw_gid:pw_gecos:pw_dir:pw_shell
Run Code Online (Sandbox Code Playgroud)
上面有 7 个字段,因此这意味着您需要 6 个:
。:
即使该字段为空,您也需要将所有字段用required分隔以创建新用户。
该命令应如下所示:
echo "vv1:myUltraSecretPassword:::::" | sudo newusers
Run Code Online (Sandbox Code Playgroud)
希望这可以帮助!