Add Multiple Users to a Group in Linux

Ever found yourself in a situation to add multiple users to a single group? 😉 I know you have 😉

Just issue below command as root & it will add all the required users to a group 😉

for user in user1 user2 user3 user4 user5; do usermod -a -G group_name $user; done

If the number of users is too long, then create a text file containing all the users to be added (make sure user names are white-space separated, just like above example) & then pass this text file in for loop. Like this 😉

for user in `cat ~shashank/users_list.txt`; do usermod -a -G group_name $user; done

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s