Changing an AIX password via script?

后端 未结 13 1879
無奈伤痛
無奈伤痛 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:20

    Use GNU passwd stdin flag.

    From the man page:

       --stdin
              This option is used to indicate that passwd should read the new password from standard input, which can be a pipe.
    

    NOTE: Only for root user.

    Example

    $ adduser foo 
    $ echo "NewPass" |passwd foo --stdin
    Changing password for user foo.
    passwd: all authentication tokens updated successfully.
    

    Alternatively you can use expect, this simple code will do the trick:

    #!/usr/bin/expect
    spawn passwd foo
    expect "password:"
    send "Xcv15kl\r"
    expect "Retype new password:"
    send "Xcv15kl\r"
    interact
    

    Results

    $ ./passwd.xp 
    spawn passwd foo
    Changing password for user foo.
    New password: 
    Retype new password: 
    passwd: all authentication tokens updated successfully.
    

提交回复
热议问题