当前位置:  技术问答>linux和unix

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

    来源: 互联网  发布时间:2017-05-24

    本文导语:  本人小白,各种不懂,求大神!!!! Solaris系统中使用使用useradd创建了用户,可是使用passwd来给用户设置密码的时候,总是不行,总要提示手动输入,我希望能否使用脚本直接完成,该怎么做呢? USERNAME="testuser" P...

本人小白,各种不懂,求大神!!!!

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

USERNAME="testuser"
PASSWORD="q1w2e3"

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

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


求大神帮助!!!!!

|
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

|
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... :)

    
 
 

您可能感兴趣的文章:

 
本站(WWW.)旨在分享和传播互联网科技相关的资讯和技术,将尽最大努力为读者提供更好的信息聚合和浏览方式。
本站(WWW.)站内文章除注明原创外,均为转载、整理或搜集自网络。欢迎任何形式的转载,转载请注明出处。












  • 相关文章推荐
  • 感谢sharptop版主提供的webchart,给分了!请版主进入!
  • to:可怜的NB的夜叉先生:请版主不要del
  • 申请本版版主... ...
  • 大家都来给我们的版主扎起![分多得烧]
  • 麻烦版主帮我结了这个贴
  • 欢迎大家到c/c++ 面向对象去作客(请版主不要删)
  • 兄弟给我解决问题,我来给分了,版主别封号呀!
  • 急切等待版主解决
  • unix/linux知识 iis7站长之家
  • 大家来给版主扎起[分多得烧]
  • 请版主和各位高手提建议
  • 诚邀版主,欢迎使用QT编程的同志!!!!!!!
  • 乱码的帖子严重影响了版面,版主该考虑删删了吧
  • 我想申请DOS论坛版主,请大家多多支持!
  • 版主救命,救命如救火,
  • 各位版主,请进,谢了!
  • 出来埠到,以前在bcb,还捞了小版主,这里只是新兵。
  • 版主上岗例会...散分...
  • 【版主】新来一个Linux学习网站 http://www.go2linux.cn/ 散分
  • 版主的版规贴不能回复,锁住了。


  • 站内导航:


    特别声明:169IT网站部分信息来自互联网,如果侵犯您的权利,请及时告知,本站将立即删除!

    ©2012-2021,,E-mail:www_#163.com(请将#改为@)

    浙ICP备11055608号-3