Languages
[Edit]
EN

Linux - add user to specific group

6 points
Created by:
Shri
8340

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).

Quick solution:

usermod -a -G new-group some-user

Where:

  • -a - adding new group,
  • -G - other user groups modification (not main user group),
  • new-group - new group assigned to some-user,
  • some-user - name of user that we modify.

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 sudo group.

Note be sure you are logged-in as user with special permissions, e.g. super user / root.

  1. If you are not, login to root account with command:
    su

    It will ask you to type root password and press enter key:

    john@ubuntu-pc:~$ su
    Password: 
  2. Then add user to group with command:
    usermod -a -G sudo john

    Note: sudo group can be replaced with any existing group name.

  3. Then check if the user has been attached to the group with command:
    groups john

    It should return something similar:

    root@ubuntu-pc:/home/john# groups john
    john : john cdrom sudo

    If sudo group name is printed it means we are in the group.

Donate to Dirask
Our content is created by volunteers - like Wikipedia. If you think, the things we do are good, donate us. Thanks!
Join to our subscribers to be up to date with content, news and offers.

Linux

Native Advertising
🚀
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

â€ïžđŸ’» 🙂

Join