Changing an AIX password via script?

后端 未结 13 1904
無奈伤痛
無奈伤痛 2020-12-23 16:43

I am trying to change a password of a user via script. I cannot use sudo as there is a feature that requires the user to change the password again if another user changes th

13条回答
  •  情歌与酒
    2020-12-23 17:16

    This is from : Script to change password on linux servers over ssh

    The script below will need to be saved as a file (eg ./passwdWrapper) and made executable (chmod u+x ./passwdWrapper)

    #!/usr/bin/expect -f
    #wrapper to make passwd(1) be non-interactive
    #username is passed as 1st arg, passwd as 2nd
    
    set username [lindex $argv 0]
    set password [lindex $argv 1]
    set serverid [lindex $argv 2]
    set newpassword [lindex $argv 3]
    
    spawn ssh $serverid passwd
    expect "assword:"
    send "$password\r"
    expect "UNIX password:"
    send "$password\r"
    expect "password:"
    send "$newpassword\r"
    expect "password:"
    send "$newpassword\r"
    expect eof
    

    Then you can run ./passwdWrapper $user $password $server $newpassword which will actually change the password.

    Note: This requires that you install expect on the machine from which you will be running the command. (sudo apt-get install expect) The script works on CentOS 5/6 and Ubuntu 14.04, but if the prompts in passwd change, you may have to tweak the expect lines.

提交回复
热议问题