0

I know there are various ways of updating the password of a user with a script. I am looking for a way to set a default password for a new user.

/etc/default/useradd doesn't help

I don't want to set a cron that would execute a chpasswd or passwd, unless that's really the only way.

Any idea?

2 Answers 2

0

Useradd does not support this, however you can just chain some commands to achieve this effect:

useradd <USER> && echo <USER>:<PASS> | chpasswd

3
  • Ok but that's exactly what i want to avoid. When any user is created using useradd or adduser or anything else, I want the system to set a default password.
    – momeunier
    Commented Mar 15, 2014 at 11:40
  • @momeunier: You seem to be assuming that user accounts are added by "the system" and everything else just gives requests to do so. This is incorrect. With regular local Unix accounts (/etc/passwd and /etc/shadow), the useradd command edits the files directly, and it's entirely up to useradd what password will be set. If useradd does not have a function to pre-set a password, then you cannot convince it to do so, except by adding such a function to useradd's source code. (adduser is only a script that calls useradd, so it would get this automatically. No guarantees about other tools.) Commented Mar 15, 2014 at 12:31
  • good point... I didn't really ask myself the right question.
    – momeunier
    Commented Mar 15, 2014 at 13:16
0

The above has some limitation, alternatively I found solution proposed here https://askubuntu.com/a/80447/1128059 is more reliable

usermod --password $(echo MY_NEW_PASSWORD | openssl passwd -1 -stdin) USERNAME

You must log in to answer this question.

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