I would like to add new user without needed any interaction, so with specified password. I have tried command above:

useradd -m -p user -s /bin/bash user

So it should be a user with password user, but I can't login via SSH.


Read the man page. The argument to -p is not the plaintext password:

-p, --password PASSWORD

The encrypted password, as returned by crypt(3). The default is to disable the password.

and it would be an extremely dangerous command if it were. There is no easy way to do what you want, because what you want is dangerous.

Edit: I understand that you feel your circumstances justify this loss of security, and you might be right: but there is no way for the passwd command to know what you're thinking.

If you're sure you don't mind this loss of security, you could do

echo fr00zalgn3t | passwd --stdin user

to set the initial password to the echoed string, but if you do this, you should also do

chage -d 0 user

immediately after, to require that the password be changed on first login. You should also ensure that your shell history is cleared after doing this, so the passwords used aren't sitting in a permanent record on-disc. And you should not, ever, use the username as an initial password, no matter how low-end you feel the system is.

  • It would be a test system and it should be an initial password. – plaidshirt Dec 3 '15 at 9:10
  • I gather from other similar posts on SE that the preferred way on Linux nowadays is to use chpasswd. You may see how-tos on the web suggesting openssl passwd -crypt, or variations of that, but there are too many combinations of hashes and salts that will probably depend on your particular distro. Save yourself the headache. – TheDudeAbides Mar 8 at 1:03
  • Additionally, security is always a compromise. I personally feel perfectly fine setting passwords in this way for private / internal / test systems, provided they're good (random) initial passwords, the user is forced to change the password upon first login (as you mention, with chage, or the account is short-lived. – TheDudeAbides Mar 8 at 1:03

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.