I know that when creating a new user by useradd, I could set his password by -p option, but it seems insecure, then what the right way to create a user and set his password?

I do this in two steps:

1. create the user using useradd command without the -p option
2. set the user's password using passwd command

is this two steps suitable?

2 Answers 2


The -p option takes a crypted password. This is exposed in process listings/etc. so is not ideal, though it is just the hash.

You could use 'chpasswd' if you're creating the user in an automated fashion - since it will take either a crypted or plaintext passwd on stdin.

The best approach depends on the circumstances. If you're just casually creating an account, then useradd followed by passwd command is probably the simplest option.


If your platform has it (and it probably does), adduser is a nice higher-level front-end for useradd. It can prompt for a password, like passwd (in fact, it just calls the native passwd program), as well as for GECOS info, etc. (You can also run it in batch mode, at which point you might as well just use useradd.)

  • adduser exist in debian but not in redhat, I don't want to learn both these two command, since adduser is based on useradd, I want just learn useradd...
    – cifer
    Jan 20, 2014 at 5:27

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.