{"id":1534,"date":"2021-12-16T14:17:44","date_gmt":"2021-12-16T11:17:44","guid":{"rendered":"https:\/\/files2.tojikon.net\/files-cloud\/2021\/05\/20\/how-to-use-usermod-to-add-users-to-groups-in-linux\/https:\/\/files2.tojikon.net\/files-cloud\/2021\/05\/20\/how-to-use-usermod-to-add-users-to-groups-in-linux\/"},"modified":"2021-12-16T14:17:44","modified_gmt":"2021-12-16T11:17:44","slug":"how-to-use-usermod-to-add-users-to-groups-in-linux","status":"publish","type":"post","link":"https:\/\/tojikon.net\/en\/1534-how-to-use-usermod-to-add-users-to-groups-in-linux\/","title":{"rendered":"How to use usermod to add users to groups in Linux"},"content":{"rendered":"<section id=\"related_posts\">\n<div class=\"block-head\">\n<h3>Related Articles<\/h3>\n<\/div>\n<\/section>\n<p>Do you need to add users to groups on your Linux PC or Linux server? Don\u2019t understand how the group system works and need some guidance? We can help! Follow along with this guide as we show you how to add users to groups with the \u201cusermod\u201d tool on Linux!<\/p>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"alignnone wp-image-402313 size-full\" src=\"https:\/\/files2.tojikon.net\/files-cloud\/wp-content\/uploads\/2021\/12\/how-to-use-usermod-to-add-users-to-groups-in-linux.png\" alt=\"add users to groups in Linux\" width=\"1200\" height=\"707\"\/><\/p>\n<p>Need to view all users on a Linux system? Follow this guide.<\/p>\n<h2>Adding users to existing groups with usermod\u00a0<\/h2>\n<p>If you need to add a user to an existing group on your Linux PC, the first step is to list the groups on the system. You can find out if the group you expect to add the user to is on the system and how it is spelled by listing groups.<\/p>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"alignnone wp-image-402312 size-full\" src=\"https:\/\/files2.tojikon.net\/files-cloud\/wp-content\/uploads\/2021\/12\/how-to-use-usermod-to-add-users-to-groups-in-linux-1.png\" alt=\"\" width=\"1200\" height=\"666\"\/><\/p>\n<p>To view a list of existing groups on your Linux PC, execute the <strong>cut<\/strong> command. This command will print out every group you have into the terminal, and you can use it to locate the group you want to add users to with it.<\/p>\n<pre>\ncut -d: -f1 \/etc\/group\n<\/pre>\n<p>If there are a whole lot of groups and you want an easier way to sort through them, try running it with the\u00a0<strong>less\u00a0<\/strong>command.\u00a0<\/p>\n<pre>\ncut -d: -f1 \/etc\/group | less\n<\/pre>\n<p>When you\u2019ve found the existing group, you wish to add your user to using the <strong>usermod -a -G\u00a0<\/strong>command. This command will allow the specified user account to be bound to any group you want to.\u00a0<\/p>\n<p>For example, to add the user addictivetips to the group \u201ctech,\u201d you could enter the\u00a0<strong>usermod -a -G\u00a0<\/strong>command with the \u201ctech\u201d group to add the user to the group.<\/p>\n<pre>\nsudo usermod -a -G tech addictivetips\n<\/pre>\n<p>The\u00a0<strong>usermod\u00a0<\/strong>command isn\u2019t limited to a single group. Users can add a single user to many groups at a time in the same command. For example, if you wish to add the \u201caddictivetips\u201d user to the groups \u201ctech,\u201d \u201cvideo,\u201d and \u201csound,\u201d you can by simply listing all groups before the username. There isn\u2019t a limit to how many groups can be added to a user at a time.<\/p>\n<pre>\nsudo usermod -a -G tech video sound addictivetips\n<\/pre>\n<p>To add your own groups to a user, take the\u00a0<strong>usermod -a -G\u00a0<\/strong>command above and change the examples to fit your use case. Be sure to do this for each user you wish to add to existing groups on Linux!<\/p>\n<h2>Adding users to new groups with usermod<\/h2>\n<p>Along with adding users to existing groups, adding users to new groups using the usermod command is also possible. To start, you\u2019ll need to create a new group. To create a new group, you will need to use the <strong>groupadd\u00a0<\/strong>command.<\/p>\n<p>To create a new group, open up a terminal window. To open up a terminal window on the Linux desktop, press\u00a0<strong>Ctrl + Alt + T\u00a0<\/strong>on the keyboard. Or, search for \u201cTerminal\u201d in the app menu and use it that way.<\/p>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"alignnone wp-image-402313 size-full\" src=\"https:\/\/files2.tojikon.net\/files-cloud\/wp-content\/uploads\/2021\/12\/how-to-use-usermod-to-add-users-to-groups-in-linux.png\" alt=\"\" width=\"1200\" height=\"707\"\/><\/p>\n<p>With the terminal app open and ready to use, run the <strong>groupadd<\/strong> command to create your new group. The group can be named anything you like. However, be sure you know why you\u2019re making the group and that it has a function. Otherwise, you may accidentally delete your group at a later date without understanding why.<\/p>\n<pre>\nsudo groupadd mynewgroup\n<\/pre>\n<p>Upon entering the\u00a0<strong>groupadd\u00a0<\/strong>command, your Linux system will likely ask you for your password. You will need to enter your password. Using the keyboard, enter your user account password and press the\u00a0<strong>Enter\u00a0<\/strong>key to continue.<\/p>\n<p>Once you\u2019ve created your new group, run the\u00a0<strong>cut<\/strong> command to view your new group. It\u2019s very important to confirm that the new group you\u2019ve just created exists on the system. If it doesn\u2019t show up, you won\u2019t be able to add a user to it, and the group will need to be made again.<\/p>\n<p>To view all groups on your Linux system, run the following\u00a0<strong>cut\u00a0<\/strong>command, and add on the\u00a0<strong>grep\u00a0<\/strong>command to filter through the long list of existing groups for the one you created.\u00a0<\/p>\n<pre>\nsudo cut -d: -f1 \/etc\/group | grep mynewgroup\n<\/pre>\n<p>The\u00a0<strong>cut\u00a0<\/strong>command will return your group name if it has been made successfully. If it hasn\u2019t, nothing will happen with the command run.<\/p>\n<p>Once you\u2019ve confirmed that your new group is on your Linux system, you can assign a user to it. For example, add the \u201caddictivetips\u201d user to the \u201cmynewgroup\u201d we just created and execute the following <strong>usermod\u00a0<\/strong>command below.<\/p>\n<pre>\nsudo usermod -a -G mynewgroup addictivetips\n<\/pre>\n<h2>Remove users from groups<\/h2>\n<p>If at any time you need to remove a Linux user from a group, you can make use of the <strong>gpasswd\u00a0<\/strong>command. For example, to remove the \u201caddictivetips\u201d user from the \u201cmynewgroup\u201d group, you\u2019d execute the command below.<\/p>\n<pre>\nsudo gpasswd -d addictivetips mynewgroup\n<\/pre>\n<p>Enter the command above any time you need to remove a Linux user from a group on the system.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Related Articles Do you need to add users to groups on your Linux PC or Linux server? Don\u2019t understand how the group system works and need some guidance? We can help! Follow along with this guide as we show you how to add users to groups with the \u201cusermod\u201d tool on Linux! Need to view &hellip;<\/p>\n","protected":false},"author":1,"featured_media":1535,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[21],"tags":[33],"_links":{"self":[{"href":"https:\/\/tojikon.net\/en\/wp-json\/wp\/v2\/posts\/1534"}],"collection":[{"href":"https:\/\/tojikon.net\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/tojikon.net\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/tojikon.net\/en\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/tojikon.net\/en\/wp-json\/wp\/v2\/comments?post=1534"}],"version-history":[{"count":0,"href":"https:\/\/tojikon.net\/en\/wp-json\/wp\/v2\/posts\/1534\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/tojikon.net\/en\/wp-json\/wp\/v2\/media\/1535"}],"wp:attachment":[{"href":"https:\/\/tojikon.net\/en\/wp-json\/wp\/v2\/media?parent=1534"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/tojikon.net\/en\/wp-json\/wp\/v2\/categories?post=1534"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/tojikon.net\/en\/wp-json\/wp\/v2\/tags?post=1534"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}