Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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?

share|improve this question
up vote 0 down vote accepted

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.

share|improve this answer

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

share|improve this answer
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... – cli__ Jan 20 '14 at 5:27

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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