linux – 编写脚本以使用预定义的密码创建多个用户

linux – 编写脚本以使用预定义的密码创建多个用户,第1张

概述所以我想创建一个脚本,用于运行users.txt中的用户 useradd -m -s /bin/false users_in_the_users.txt 并从passwords.txt填写密码两次(以确认密码) 这是脚本 #!/bin/bash# Assign file descriptors to users and passwords filesexec 3< users.txtexe 所以我想创建一个脚本,用于运行users.txt中的用户

useradd -m -s /bin/false users_in_the_users.txt

并从passwords.txt填写密码两次(以确认密码)

这是脚本

#!/bin/bash# Assign file descriptors to users and passwords filesexec 3< users.txtexec 4< passwords.txtexec 5< passwords.txt# Read user and passwordwhile read iuser <&3 && read ipasswd <&4 ; do  # Just print this for deBUGging  printf "\tCreating user: %s with password: %s\n" $iuser $ipasswd  # Create the user with adduser (you can add whichever option you like)  useradd -m -s /bin/false $iuser  # Assign the password to the user,passwd must read it from stdin  passwd $iuserdone

问题是,它没有填写密码.还有一件事,我希望脚本能够填写两次密码.

有什么建议?

解决方法 您必须在stdin上提供密码.更换:

passwd $iuser

有:

passwd "$iuser" <<<"$ipasswd$ipasswd"

或者,如mklement0所示:

passwd "$iuser" <<<"$ipasswd"$'\n'"$ipasswd"

咒语<<<创建一个here-string. <<<<<<<<<作为标准提供给<<<<<<<<在这种情况下,我们提供passwd命令所需的密码的两个副本. (该脚本从纯文本文件中读取这些密码.我将假设您的情况是一些特殊情况,而这种情况并不像通常那样危险.)

总结

以上是内存溢出为你收集整理的linux – 编写脚本以使用预定义的密码创建多个用户全部内容,希望文章能够帮你解决linux – 编写脚本以使用预定义的密码创建多个用户所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/yw/1023872.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-23
下一篇 2022-05-23

发表评论

登录后才能评论

评论列表(0条)

保存