Ferry Boender

Programmer, DevOpper, Open Source enthusiast.

Email: ferry.boender@gmail.com
Github: https://www.github.com/fboender
Résumé: PDF, Dutch
PGP key: PGP key
Blog: Electricmonk.nl
Keybase: fboender

Batch create new users on Linux

Sunday, October 4th, 2015

A while ago I had to create many new users on a Linux machine. Since I'm lazy, I opted to automate this process. The newusers command combined with pwgen (to generate new passwords) was the solution.

First I installed pwgen, a utility to automatically generate passwords:

$ sudo apt-get install pwgen

I created a file with the new user names to create.

$ cat newusers.txt

A simple shell one-liner generates a new file from this in the right format for the newusers tool:

$ for USER in $(cat newusers.txt); do 
  echo "$USER:$(pwgen 12 -n1)::::/home/$USER:/bin/bash" >> newusers.created.txt;

Finally, we create the new users:

$ sudo newusers newusers.created.txt

The newusers.created.txt file was handed over to the person in charge of notifying the users about their new account.

The text of all posts on this blog, unless specificly mentioned otherwise, are licensed under this license.