1

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.

1

1 Answer 1

5

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.

5
  • Thanks! But how how do I encrypt the password to linux specifications?
    – Flashuni
    Jun 27, 2011 at 20:05
  • The 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.
    – Flimzy
    Jun 27, 2011 at 20:09
  • you can get other details on encryption by running man passwd .
    – thinice
    Jun 27, 2011 at 22:00
  • 2
    Not 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. Jun 28, 2011 at 5:29
  • You need to argue that with the author of the useradd man page--all Unix systems do that. crypt always outputs a hash.
    – Flimzy
    Jun 28, 2011 at 5:32

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .