BASH – Automate the creation/deletion of multiple users

The script goes through a list of names and creates the logins for them. This type of script is useful if you have to enter a plethora of users.

For example you may be give a file with 20 names in  the following format:

  • George Mastrokostas
  • Mark Twain
  • Mary Jane
  • Janis Joplin

Having to manually enter each one of these users is tedious, boring and time consuming. The process can be automated with the following script.

You will need to create and to place the file with the names to be converted into user logins into a file called logins. The script will read the names from the file and format them.
So for example the name  George Mastrokostas will be formatted as GMastrokostas.
In addition the default password of koukla25408 will be set for all users. This option is a huge security risk and as such you can freely delete the line “echo koukla25408 | passwd $loop_user –stdin”. However the login will be created but it will not have a password in which case you will have to enter it manually for that user.
In a future release the password will be a random password for each user and it will be emailed to that user. 
You can download the scripts from the links below. You will have to save them with a .sh extension and give the executable permissions.
The second script deletes all users along with their home directories from the same list users listIt goes with out saying you can modify the list for this particular script to have the logins of your choice.
These scripts are for learning purposes only and are not meant to be used in a production system.
user_add script
user_remove script

 

 

Share Button

Leave a Reply

Your email address will not be published.

Time limit is exhausted. Please reload the CAPTCHA.