Shell-script - Create multiple user same as in another server, Bash script to crete user with password
Create multiple user same as in another server
How to create multiple users same as in another server?Sometime you might get a requirement to creare users same as in another server. At thet time you can use the below script to create users same as in another server. For creating such list you have to copy the specified userlist from the server1 and paste it in a file on server2. Lets name that file as userlist.txt
Command to grep the user and list in server1
# grep -e '/home' /etc/passwd
Copy the lines and paste it on a file in server2
# vim userlist.txt
Script to create multiple users same as in another server
password="mypassword" pass=$(perl -e 'print crypt($ARGV[0], "password")' $password) while read line do user_name="$(echo $line | cut -d: -f1)" user_id="$(echo $line | cut -d: -f3)" user_details="$(echo $line | cut -d: -f5 )" user_dir="$(echo $line | cut -d: -f6 )" useradd -m -d $user_dir -u $user_id -c "$user_details" -s /bin/bash -p $pass $user_name echo "User Name = $user_name" echo "User Id = $user_id" echo "User Details = $user_details" echo "User Home Directory = $user_dir" echo "--------------------------------------" done<names.txt
The above script will create the user with password. The variable pass has the encrypted password "mypassword", The script creates the user with specified home directory and the user comment. The -p option is used to specify the password.
The topic on Shell-script - Create multiple user same as in another server is posted by - Math
Hope you have enjoyed, Shell-script - Create multiple user same as in another serverThanks for your time