Ben Chuanlong Du's Blog

And let it direct your passion with reason.

Add Users to a Group in Linux

There are several ways to add users to a group in Linux. The following uses the sudo group as illustration.

  1. gpasswd, usermod and adduser can all be used to add a user to a given group. However, it is suggested that you use gpasswd as it is more portable and intuitive.

    gpasswd -a user_name sudo
    newgrp sudo
    
    usermod -aG sudo user_name
    newgrp sudo
    
    # works on Ubuntu but not CentOS
    adduser user_name sudo
    newgrp sudo
    

    Just adding an user to a group might not make it work right away. The command newgrp sudo make the group sudo in effect right away. Of course, you can log out and then log in to make it work.

  2. Some desktop environment (e.g., GNome, Cinnamon, KDE, etc.) can also do this for you. Taking Cinnamon as an example, you can follow the steps below to add/remove groups for a user.

    1. Open System Settings.

    2. Click Users and Groups.

    3. Select the user you want modify.

    4. Click on Groups.

    5. Check/uncheck groups from the prompt list.

    6. Click the OK to save the changes.

Comments