Bash 循环新用户

2 linux bash programming

我必须在 10 台服务器上创建 20 个用户。我想创建一个脚本,它将在服务器上为我创建 20 个用户(使用 很容易useradd)并加密密码。我有我的变量

$crypt=perl -e 'print crypt...'

现在我想创建一个循环来创建新用户,密码将由$crypt.

我怎么能做到这一点?

小智 5

设置地穴

crypt=$(perl -e'print crypt("somekey", "salt_character")')
Run Code Online (Sandbox Code Playgroud)

在 for 循环中调用用户名列表并传递 $crypt 作为密码。

for i in `cat usernamelist`
 do
    useradd $i -p $crypt
done
Run Code Online (Sandbox Code Playgroud)

从手册页,

-p, --password PASSWORD
          The encrypted password, as returned by crypt(3). The default is to disable the account.
Run Code Online (Sandbox Code Playgroud)