Pass password to adduser command
7,990
You cannot do this with the adduser
command, however you can with the underlying useradd
command, if you have the crypted version of the password:
useradd <username> -p <crypted password>
You will likely want to include other options on the useradd command line, to set up groups, etc. Read the useradd(8) man page for details.
You could also do this with usermod
, after having used adduser
to initially create the account, if that's easier for you.
Related videos on Youtube
Author by
Flashuni
Updated on September 18, 2022Comments
-
Flashuni over 1 year
Just wondering if it's possible to pass the password I want to use to the adduser command in ubuntu, so that it can be automated.
I want to do something like this
echo "password" | adduser test
This would eliminate the need to fill out the form needed for the adduser command and set the password, "password", for the "test" user.
-
Zoredache almost 13 years
-
-
Flashuni almost 13 yearsThanks! But how how do I encrypt the password to linux specifications?
-
Flimzy almost 13 yearsThe usradd(8) man page tells you: "The encrypted password, as returned by crypt(3)." Most systems have the 'crypt' command installed which will output the format you need.
-
thinice almost 13 yearsyou can get other details on encryption by running
man passwd
. -
Slartibartfast almost 13 yearsNot to be pedantic or anything, but Ubuntu systems use hashing and not encryption to securely store passwords. It may seem like a silly distinction, especially when we are talking about cryptographically secure hashes, but if you intend to do any security work at all, it will trip you up down the road. Cryptography goes two ways. Hashes only go one way.
-
Flimzy almost 13 yearsYou need to argue that with the author of the useradd man page--all Unix systems do that. crypt always outputs a hash.