6

In Ubuntu, there is a GUI option when creating new users:

  1. Allow user to set a password when they next login
  2. Set a password now

What would be the command line equivalent to this ?

From what I've been able to determine, useradd or adduser don't provide this option.

I know I can set a password and expire it forcing the user to change it but that's not the same thing exactly.

This would be for NEW users who have never logged on, and giving them the privilege to set their password for themselves at the first login.

I know if the GUI can do it can be done, but can't find it anywhere in man pages or internet searches.....

2
  • Welcome, I think you are looking for sudo passwd -e username. May 28 at 15:57
  • I found that if I combine passwd -d the passwd -e, I get the desired result. The command would be passwd -de $USER passwd -d removes the password passwd -e expires the password Then, when the user goes to login the the FIRST time there is NO password in existence but the machine requires that user to set one. This eliminates me having to set a bogus passwd like "PASSWORD" and telling the USER that so they can login and change it something of their own choosing.
    – yegnal
    May 29 at 16:17

1 Answer 1

7

There's a program called passwd that does that: change your own password, or if you're root, change any user's password.

sudo passwd -e yegnal can be used to set a password for the user yegnal to expire the next time they log in (so they have to pick a new one).

-d sets the user passwordless – so anyone can login without a password. So, sudo passwd -d -e yegnal will make yegnal be passwordless and enforce setting a new password next time they log in.

A note on security: it's probably a bad idea to set up a user account without a password, no matter whether you do it via GUI or CLI. What's the point? Creating a user takes literally seconds, so you can create one (eg. logged in as root via SSH from afar) whenever you need one, and use a random password that you expire instantly and share with the new human user anyways.

2
  • I found that if I combine passwd -d the passwd -e, I get the desired result. The command would be passwd -de $USER passwd -d removes the password passwd -e expires the password Then, when the user goes to login the the FIRST time there is NO password in existence but the machine requires that user to set one. This eliminates me having to set a bogus passwd like "PASSWORD" and telling the USER that so they can login and change it something of their own choosing.
    – yegnal
    May 29 at 16:16
  • 1
    as said, that's not good security practice, but you do you! any password, even just two words from a dictionary that are easy to tell, is better than no password. May 29 at 16:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.