0

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?

cifer
  • 103
  • 4

2 Answers2

1

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

Bandrami
  • 893
  • 4
  • 8
  • 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 '14 at 05:27
0

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.

Nathan Neulinger
  • 597
  • 1
  • 5
  • 16