The following tutorial Linux add user to group explains how to add a new or existing user to a new or existing group under Linux operating system using command line interface / SSH. First let me tell you that there are two categories of users in Linux OS i.e. primary and secondary. So I will explain add new and existing users to both primary and secondary group side by side. Here we go:-
- Linux add user to group (New User)
- Adding an existing user to any group
LINUX ADD USER TO GROUP (NEW USER) TUTORIAL
Under linux OS “useradd” or “usermod” command is used to add a user, so following syntax can be used to add a user to any group in linux.
usermod -a -G (groupname) username
For example if we need to add a new user arshadnew to group admin then following code will be used :-
usermod -a -G admin arshadnew passwd arshadnewNote:- passwd command is to assign password for user arshadnew.
Now ensure that the user arshadnew is properly added to the group admin by following command :-
id arshadnew or group arshadnew
HOW TO LINUX: ADD AN EXISTING USER TO GROUP
If we need to add an existing user to a group then we just need the first line of above code because we do not need to setup password for the user as the user is already existed.
For example : to add an existing user arshadold to group admin then following command will be used :-
usermod -a -G admin arshadoldnote:- the user is already existed so we do not need to setup password for that.
ADDING GROUP IN LINUX
Ensure that the group to which you are adding a user should be created first or already existing.
If you need to add a group then you can use following command to add a group in linux.
Hope this tutorial linux add user to group helps you in the best way, don’t forget to share, like, comment and follow me if you like the above tutorial.