Close Menu
    Facebook X (Twitter) Instagram
    TecAdmin
    • Home
    • FeedBack
    • Submit Article
    • About Us
    Facebook X (Twitter) Instagram
    TecAdmin
    You are at:Home»Programming»Bash Shell»How to Assign Password to User in a Shell Script

    How to Assign Password to User in a Shell Script

    By RahulNovember 27, 20141 Min Read

    Command:

    echo <password> | passwd –stdin <username>

    Example:

    Use the following command to change password of user jack in a shell script. For example we are using string password as password.

    echo "password" | passwd --stdin jack
    

    Assigning User Input Password:

    Use the following commands to input password from user and assign to user jack.

    read -p "Enter Password for User jack: " pwd
    echo $pwd | passwd --stdin jack
    

    Also we can prompt password twice from user to make confirmation that user has memorize it correctly. Use the following commands to input password twic from user and assign to user jack.

    while :
    do
        read -p "Enter Password for User jack: " pwd1
        read -p "Confirm Password for User jack: " pwd2
        if [ "$pwd1" == "$pwd2" ]
        then
    		break
        else
    	    echo "Password and Confirm password doesn't match...."
        fi
    done
    echo $pwd1 | passwd --stdin jack
    

    Share. Facebook Twitter Pinterest LinkedIn Tumblr Email WhatsApp

    Related Posts

    How to Ignore SSL Certificate Check with Wget

    How to Ignore SSL Certificate Check with Curl

    echo Command in Linux with Practical Examples

    Add A Comment

    Leave A Reply Cancel Reply

    Advertisement
    Recent Posts
    • How to Change Port in Next.Js
    • Ubuntu 24.04 LTS: The Future of Open-Source Excellence
    • How to Execute Linux Commands in Python
    • Creating MySQL User with GRANT OPTION
    • Where to find crontab (cron) logs in Ubuntu & Debian
    Facebook X (Twitter) Instagram Pinterest
    © 2023 Tecadmin.net. All Rights Reserved | Terms  | Privacy Policy

    Type above and press Enter to search. Press Esc to cancel.