In this article, we're going to have a look at how to add user to specific group in Linux.
Simplest way is to use
usermod command as super user (user with special permissions).
usermod -a -G my-group-name my-user-name
Check following example to know how to do it:
1. Add user to existing group example
In this section we would like to show how add some user to avaialble group - in this example
Note be sure you are logged-in as user with special permissions, e.g. super user /
- If you are not, login to
rootaccount with command:
It will ask you to type
rootpassword and press enter key:
my-user-name@my-pc-name:~$ su Password:
- Then add user to group with command:
usermod -a -G sudo my-user-name
sudogroup can be replaced with any existing group name.
- Then check if the user has been attached to the group with command:
It should return something similar:
root@my-pc-name:/home/my-user-directory# groups my-user-name my-user-name : my-user-name cdrom sudo
sudogroup name is printed it means we are in the group.