Changing an AIX password via script?

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

    You can try :

    echo -e "newpasswd123\nnnewpasswd123" | passwd user

    0 讨论(0)
  • 2020-12-23 17:12
    printf "oldpassword/nnewpassword/nnewpassword" | passwd user
    
    0 讨论(0)
  • 2020-12-23 17:15

    You can try

    LINUX

    echo password | passwd username --stdin

    UNIX

    echo username:password | chpasswd -c

    If you dont use "-c" argument, you need to change password next time.

    0 讨论(0)
  • 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.

    0 讨论(0)
  • 2020-12-23 17:17
    Here is the script... 
    
    #!/bin/bash
    echo "Please enter username:"
    read username
    echo "Please enter the new password:"
    read -s password1
    echo "Please repeat the new password:"
    read -s password2
    
    # Check both passwords match
    if [ $password1 != $password2 ]; then
    echo "Passwords do not match"
     exit    
    fi
    
    # Does User exist?
    id $username &> /dev/null
    if [ $? -eq 0 ]; then
    echo "$username exists... changing password."
    else
    echo "$username does not exist - Password could not be updated for $username"; exit 
    fi
    
    # Change password
    echo -e "$password1\n$password1" | passwd $username
    

    Refer the link below as well...

    http://www.putorius.net/2013/04/bash-script-to-change-users-password.html
    
    0 讨论(0)
  • 2020-12-23 17:17

    For me this worked in a vagrant VM:

    sudo /usr/bin/passwd root <<EOF
    12345678
    12345678
    EOF
    
    0 讨论(0)
提交回复
热议问题