Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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

2 Answers 2

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... –  Cifer Jan 20 at 5:27

Your Answer

 
discard

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.