Facebook Twitter Instagram
    TecAdmin
    • Home
    • Ubuntu 20.04
      • Upgrade Ubuntu
      • Install Java
      • Install Node.js
      • Install Docker
      • Install LAMP Stack
    • Tutorials
      • AWS
      • Shell Scripting
      • Docker
      • Git
      • MongoDB
    • FeedBack
    • Submit Article
    • About Us
    Facebook Twitter Instagram
    TecAdmin
    Home»Linux Commands»Removing User from Secondary Group in Linux

    Removing User from Secondary Group in Linux

    RahulBy RahulNovember 26, 20142 Mins ReadUpdated:July 7, 2021

    All the groups except the primary group are called the secondary groups of Users, for whom they belong. Generally, the primary group is created at the time of user-created with the same name. You can also assign a user to other groups to inherit their group permissions.

    Syntax

    The gpasswd command uses the following syntax for removing a user from group.

    gpasswd --delete USER GROUP
    

    Change USER with your actual user name and GROUP with named of group from which you want to delete user.

    Example

    Use the following command to remove user jack from sudo group.

    gpasswd -d jack sudo  
    

    Instead of -d, you can also use its long version --delete.

    Once you deleted a user from the group, check the list of groups the user belongs to.

    cat /etc/group | grep jack  
    

    Add User to a Secondary Group

    In case you realize that you didn’t want to remove that user from the group. Also, you may be required to add another user to that group. Use the following command to add a user to a second group.

    usermod -aG sudo jack 
    

    The above command will add user “jack” to the group named “sudo”.

    Conclusion

    Hope this FAQ contains the useful information you required.

    gpasswd group user usermod
    Share. Facebook Twitter Pinterest LinkedIn Tumblr Email WhatsApp
    Previous ArticleAdding User in Secondary Group using Command in Linux
    Next Article How to Count Lines in a file in Linux

    Related Posts

    How to Search Recently Modified Files in Linux

    2 Mins Read

    Bash Printf Command

    Updated:December 23, 20212 Mins Read

    Tee Command in Linux with Examples

    4 Mins Read

    How to Scan Open Ports with Nmap

    5 Mins Read

    Handling filenames with spaces in Linux

    3 Mins Read

    How To Compare Two Files in Linux

    Updated:August 23, 20215 Mins Read

    3 Comments

    1. Diana D on May 24, 2019 4:52 pm

      Also run
      #cat /etc/group | grep jack
      This command will return all lines in the file containing user jack and
      you can see all the groups jack is member of

      Reply
    2. alex on May 12, 2018 5:32 am

      Since you used the command gpasswd .how can we get confirmed about it??
      you didnt mention any steps for that??????

      Reply
      • Rick Covert on December 15, 2018 2:16 pm

        You can verify the groups the user is a member of or the ones the user was removed from by running
        # id
        after running the
        # gpasswd -d

        command.

        Reply

    Leave A Reply Cancel Reply

    Recent Posts
    • How to Install JAVA on Ubuntu 22.04
    • Switching Display Manager in Ubuntu – GDM, LightDM & SDDM
    • Changing the Login Screen Background in Ubuntu 22.04 & 20.04
    • How To Install PHP (8.1, 7.4 or 5.6) on Ubuntu 22.04
    • (Resolved) Please install all available updates for your release before upgrading
    Facebook Twitter Instagram Pinterest
    © 2022 Tecadmin.net. All Rights Reserved | Terms  | Privacy Policy

    Type above and press Enter to search. Press Esc to cancel.