Changing an AIX password via script?

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

提交回复
热议问题