I can't understand the purpose of -p option in 'useradd'
Let's create a user

useradd -m -p 'pass1' user1 

after running the command above, when trying to log in using su - user1 authentication fails. another problem is that password is not encrypted in /etc/passwd file, if I run cat /etc/passwd | grep user1 I get user1:pass1:19196:0:99999:7:::.


1 Answer 1


You are supposed to provide the encrypted password to the -p option. From the useradd(8) man page:

       -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.

The value you provide is used verbatim in the passwd file, so of course if you provide an unencrypted value you'll never be able to log in using that password.

Something like this works:

useradd -m \
  -p "$(python -c 'import crypt; print(crypt.crypt("pass1"))')" \

(But do note the warning in the man page about potentially exposing the password to other system users.)

Not the answer you're looking for? Browse other questions tagged .