I am running ubuntu 14.04 LTS. I ran the following command to create a user

$sudo useradd -m -p password1 guest_user

and then tried to switch to the user with

$su guest_user

But i could not login with password1

Am i missing something? Am i suppose to login with password1 or something else as -p option says in the man page for useradd

 -p, --password PASSWORD
           The encrypted password, as returned by crypt(3). The default is to disable the password.

           Note: This option is not recommended because the password (or encrypted password) will be
           visible by users listing the processes.

           You should make sure the password respects the system's password policy.

The above confuses me because when i type the command

useradd -m -p password1

the password password1 is visible on the command line. How to make it invisible in the above command?


From man useradd :

-p, --password PASSWORD
           The encrypted password, as returned by crypt(3). The default is to disable the password.

As you can see the PASSWORD with -p option is the encrypted password returned by the crypt(3) library function.

If you use -p password1, the system will consider this plain text password1 as the encrypted shadow password entry in /etc/shadow.

The solution is to use the encrypted password here with -p which is unsafe, you should set the password interactively.

For example create the suer first :

sudo useradd -m -s /bin/bash guest_user

Now set the password :

sudo passwd guest_user

Or better use adduser instead :

sudo adduser --gecos '' guest_user
  • 2
    Thanks for your answer. I want to create more than 100 accounts. I don't want to set the password manually for each !!!. Secondly what is --gecos option in the adduser command? Can you explain this? Sep 1 '15 at 15:28
  • I got the gecos option but i am scratching my head on how to set password with gecos? and how to do it for 100+ users? Sep 1 '15 at 15:33
  • @user2065276 : Check this answer from karel..
    – heemayl
    Sep 1 '15 at 15:51
  • I tried Karel's post. Here is what i run into askubuntu.com/questions/667899/… Sep 1 '15 at 16:03
  • @user2065276 I see..as you have already asked a question regarding that i think you should mark this one as solved..
    – heemayl
    Sep 1 '15 at 16:05

You can use perl to print the encrypted password and use it with -p option in useradd command.

$ sudo useradd -m -p $(perl -e 'print crypt($ARGV[0], "password")' 'YOUR_PASSWORD') username

You also can use it with other options like -s for Shell or -d for home directory.


Try adding an argument after each option you want to use. For example:

    useradd -m guest_user -p passwd1

As the useradd man page suggests, adding your password in this way is not considered secure because it is transmitted in plain text. For an alternative, try:

    sudo useradd -m guest_user

and then:

    sudo passwd guest_user

Two caveats:

  • the line that begins with: NAME_REGEX= in: /etc/adduser.conf may prohibit the use of the underscore "_" character for usernames;

  • there may be password complexity requirements set in: /etc/pam.d/common-password which require a more complex password.


An alternative to doing what you want is:

$ sudo su
# useradd -m USER && echo "USER:PASSWORD" | chpasswd

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.