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.

Share:
7,990

Related videos on Youtube

Flashuni
Author by

Flashuni

Updated on September 18, 2022

Comments

  • Flashuni
    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.

  • Flashuni
    Flashuni almost 13 years
    Thanks! But how how do I encrypt the password to linux specifications?
  • Flimzy
    Flimzy almost 13 years
    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.
  • thinice
    thinice almost 13 years
    you can get other details on encryption by running man passwd .
  • Slartibartfast
    Slartibartfast almost 13 years
    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.
  • Flimzy
    Flimzy almost 13 years
    You need to argue that with the author of the useradd man page--all Unix systems do that. crypt always outputs a hash.