skip to Main Content

I am trying to automate setting up a user on centos as part of my script. Here is what i am doing:-

/usr/sbin/useradd my-user
/usr/bin/passwd my-user

You will be be prompted to enter password for the my-user user

Now is there a way to skip the second command so that there is no manual prompt, so that i can have something in the script to auto create my-user on centos without needing to manually enter the password

2

Answers


  1. You can change password programmatically, using:

    echo -e "xyznxyzn" | /usr/bin/passwd my-user
    
    Login or Signup to reply.
  2. You can use chpasswd command with echo. Here is a simple example

    /bin/echo my-user:password | /usr/sbin/chpasswd
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search