跪求版主!!!shell脚本给用户设置密码

叶吥落 2014-07-22 04:04:32
本人小白,各种不懂,求大神!!!!

Solaris系统中使用使用useradd创建了用户,可是使用passwd来给用户设置密码的时候,总是不行,总要提示手动输入,我希望能否使用脚本直接完成,该怎么做呢?

USERNAME="testuser"
PASSWORD="q1w2e3"

useradd -o -u 0 -g 0 $USERNAME
echo $PASSWORD | passwd $USERNAME

我也曾在passwd后面加上--stdin,linux下面这样就可以了,但是Solaris下就是不行,还是要提示输入密码


求大神帮助!!!!!
...全文
469 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
  • 打赏
  • 举报
回复
well, that might not be good practice in terms of security since you have passwords stored in a script file. But, whatever, here is a work around I found on google: http://www.googlux.com/scriptaddnewuser.html Instead of assigning user defined passwords, this script assign random password to users who will have to change it during the first login. The password then is sent to user by email. I heard your laugh. I was talking about potential risk of storing password in a file and now I recommend you sending initial password to users by email... :)
ljc007 2014-07-22
  • 打赏
  • 举报
回复
Solaris的passwd命令不支持--stdin或者从管道传递密码 可以使用expect模拟键盘操作,比如: http://www.unix.com/solaris/161023-solaris-passwd-script.html 也可以使用Perl的Unix::PasswdFile模块,比如: http://nixcraft.com/showthread.php/244-Change-root-password-using-perl-script

1,543

社区成员

发帖
与我相关
我的任务
社区描述
Linux/Unix社区 Solaris
社区管理员
  • Solaris
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧