2024-12-27

Creating users in Linux/Unix is ​​a straightforward task. However, adding multiple users across multiple servers can be a time-consuming task, so you can automate this with a shell script to save time or avoid manual administrative intervention.

In this bash script, we will show you how to automate user creation in Linux/Unix.

What does this script?

This script creates the below three users on multiple systems (Based on your list of servers), set password, add users to ‘2gadmins’ group and shows their password on the screen.

mageshm

tanisha

renusha

Make a Note:

Inventory: It’s dynamic, and you can Enter any number of servers, when its pops-up.

User Input: It’s dynamic, and you can add any number of users to the 'user_info' list.

Additional Switch: This is dynamic, you can add other switches if you need them. For example, the user is mapped to the '/bin/bash' shell by default, as it is already defined in the '/etc/default/useradd' file, so to change this behavior, you need to add the required shell to 'user_info', and then call it wherever needed in the script.

Remote Execution: This script works fine on a remote server as well. For Local implementation, use the 'user_add.sh' script on the specific server.

Source Bash Script for User Addition:

Remote call Bash Script:

Output:

Final Thoughts

I hope this Bash script automating user account creation in Linux, which save time and reduce manual administrative intervention. This article has provided a step-by-step guide on how to automate user account creation using Bash script.

If you have any questions or feedback, feel free to comment below.

The post How to Create Users using Shell Script in Linux first appeared on 2DayGeek.

Show more