How to automatically add user account AND password with a Bash script?

前端 未结 19 711
北荒
北荒 2020-12-07 06:53

I need to have the ability to create user accounts on my Linux (Fedora 10) and automatically assign a password via a bash script(or otherwise, if need be).

It\'s eas

相关标签:
19条回答
  • 2020-12-07 07:45

    You can use expect in your bash script.

    From http://www.seanodonnell.com/code/?id=21

    #!/usr/bin/expect 
    ######################################### 
    #$ file: htpasswd.sh 
    #$ desc: Automated htpasswd shell script 
    ######################################### 
    #$ 
    #$ usage example: 
    #$ 
    #$ ./htpasswd.sh passwdpath username userpass 
    #$ 
    ###################################### 
    
    set htpasswdpath [lindex $argv 0] 
    set username [lindex $argv 1] 
    set userpass [lindex $argv 2] 
    
    # spawn the htpasswd command process 
    spawn htpasswd $htpasswdpath $username 
    
    # Automate the 'New password' Procedure 
    expect "New password:" 
    send "$userpass\r" 
    
    expect "Re-type new password:" 
    send "$userpass\r"
    
    0 讨论(0)
提交回复
热议问题