Create or update users in bash
When preparing labs or courses I sometimes need to batch create user accounts. For this I use the command newusers. Since passwords are stored in clear text you might not want to use it in a production environment, but to give it some protection you can make sure only root can read/write to it:
touch add-users.txt
chmod 0600 add-users.txt
To create the users lists:
vi add-users.txt
Then add the info in the same format as the passed file, below is an example.
micke:MySecretPassword:1000:1000:micke:/home/micke:/bin/bash
michael:MySecretPassword:1001:1001:michael:/home/michael:/bin/bash
Then create the users:
newusers add-users.txt
You can verify by checking that the file /etc/passwd is updated.
Leave a Reply