Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to create a user using command line with setting to create password upon first login?

I am currently trying to set up a computer lab for an educational environment. I am hoping to use a combination of python and bash scripts to implement the users on all of the computers, and I was hoping to have this set so that the students would create their passwords during their first login. I would have assumed this was possible as it is the default setting when creating users through the GUI in settings. I am having issues though.

The command sudo adduser <user> desires a password be created immediately. This can be bypassed by pressing enter multiple times, but that seems like it would be an issue for my script.

The command sudo useradd <user> gets me closer, as I can afterwards use the command sudo passwd -d <user> to set it as a no password account. I can then use the command sudo passwd -e <user> to set the password to be created upon login. However, it appears the useradd command does not create a user directory on the home directory. In addition, the test showing the user and name of the computer is gone when I enter terminal, which concerns me.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

If you want them to set the password when they first login, then you’re not necessarily worried about "security" until they set their password, so create the users with a generic/default password.

then use the chage command on each account. With a script it should be a simple loop.

-d and -m are used with useradd to define and create the user directory. See man useradd for more help.

This command should be able to be used to add the user and password

# useradd -p $(openssl passwd -1 $PASS) $USER

You can add other parameters to that as needed, like the -d for defining a user directory or -m for creating the user directory

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading