Useradd with given password
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.
Related videos on Youtube
![plaidshirt](https://i.stack.imgur.com/lVkJs.jpg?s=256&g=1)
plaidshirt
Updated on September 18, 2022Comments
-
plaidshirt almost 2 years
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 passworduser
, but I can't login via SSH. -
TheDudeAbides over 5 yearsI 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 suggestingopenssl 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 over 5 yearsAdditionally, 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.