{"id":22655,"date":"2023-10-27T17:48:24","date_gmt":"2023-10-27T17:48:24","guid":{"rendered":"https:\/\/linuxways.net\/?p=22655"},"modified":"2023-10-27T17:49:48","modified_gmt":"2023-10-27T17:49:48","slug":"how-to-create-groups-in-linux-groupadd-command","status":"publish","type":"post","link":"https:\/\/linuxways.net\/de\/linux-commands\/how-to-create-groups-in-linux-groupadd-command\/","title":{"rendered":"How to Create Groups in Linux (groupadd Command)?"},"content":{"rendered":"<p>As Ubuntu is a MultiUser Operating System, it also allows the creation of multiple user Groups. System Administrators while working with multiple users, have to restrict resource or file sharing to specific users or specific types of users. Thus, specific types of users are added or assigned to one group which eases the system administrator to keep track of users.<\/p>\n<p>In this article, the methods by which the \u201cgroupadd\u201d command can be used are discussed.<\/p>\n<h2><strong>How to Create Groups in Linux (groupadd Command)?<\/strong><\/h2>\n<p>The \u201c<strong>groupadd<\/strong>\u201d is a useful command in Ubuntu to create and manage groups. It adds the newly created group to the \u201c\/etc\/group\u201d path. The basic syntax to use the \u201cgroupadd\u201d command is:<\/p>\n<div class=\"codecolorer-container bash blackboard\" style=\"width:100%;\"><div class=\"bash codecolorer\">groupadd <span class=\"sy0\">&lt;&lt;<\/span>strong<span class=\"sy0\">&gt;<\/span>option<span class=\"sy0\">&lt;\/<\/span>strong<span class=\"sy0\">&gt;&gt;<\/span> <span class=\"sy0\">&lt;&lt;<\/span>strong<span class=\"sy0\">&gt;<\/span>groupName<span class=\"sy0\">&lt;\/<\/span>strong<span class=\"sy0\">&gt;&gt;<\/span><\/div><\/div>\n<p>The \u201coptions\u201d statement is used to make the \u201cgroupadd\u201d command flexible in many different ways. Some of the popular \u201coptions\u201d with the \u201cgroupadd\u201d command are:<\/p>\n<ul>\n<li>\u201c<strong>-f<\/strong>\u201d: Forcefully Assigns or Overwrites an Existing Group.<\/li>\n<li>\u201c<strong>-g<\/strong>\u201d: Assigns a Custom Group ID to a New Group.<\/li>\n<li>\u201c<strong>-K<\/strong>\u201d: Overrides the Default Values assigned to a New Group.<\/li>\n<li>\u201c<strong>-p<\/strong>\u201d: Sets Password for a New Group.<\/li>\n<\/ul>\n<p>Below are the different methods in which the \u201cgroupadd\u201d command can be used:<\/p>\n<ul>\n<li>Use \u201cgroupadd\u201d to Create a New Group with the Default Configuration.<\/li>\n<li>Use \u201cgroupadd\u201d to Overwrite or Replace an Existing Group.<\/li>\n<li>Use \u201cgroupadd\u201d to Assign a Custom Group ID to a New Group.<\/li>\n<li>Use \u201cgroupadd\u201d to Assign a Password to a New Group.<\/li>\n<li>Use \u201cgroupadd\u201d to Create a New Group with a Custom Configuration.<\/li>\n<\/ul>\n<p>All the mentioned methods are explained in detail.<\/p>\n<h2><strong>Creating a New Group Using the \u201cgroupadd\u201d Command<\/strong><\/h2>\n<p>A new user group in Ubuntu with default configuration can be created simply by using the name of the group with the \u201cgroupadd\u201d command. In our case, we have created a new user group \u201cgroupX\u201d with the \u201cgroupadd\u201d Command that will have the default group values:<\/p>\n<div class=\"codecolorer-container bash blackboard\" style=\"width:100%;\"><div class=\"bash codecolorer\"><span class=\"kw2\">sudo<\/span> groupadd groupX<\/div><\/div>\n<p>The command line moves to the next line indicating the new group \u201cgroupX\u201d is created:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"725\" height=\"89\" class=\"wp-image-22656\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22655-1.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22655-1.png 725w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22655-1-300x37.png 300w\" sizes=\"auto, (max-width: 725px) 100vw, 725px\" \/><\/p>\n<p>To view if the newly created group was added to the system or not, use the \u201ccat\u201d command to list all the groups in Ubuntu:<\/p>\n<div class=\"codecolorer-container bash blackboard\" style=\"width:100%;\"><div class=\"bash codecolorer\"><span class=\"kw2\">cat<\/span> <span class=\"sy0\">\/<\/span>etc<span class=\"sy0\">\/<\/span>group<span class=\"sy0\">\/<\/span><\/div><\/div>\n<p>This will list all the groups in the Terminal:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"733\" height=\"421\" class=\"wp-image-22657\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22655-2.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22655-2.png 733w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22655-2-300x172.png 300w\" sizes=\"auto, (max-width: 733px) 100vw, 733px\" \/><\/p>\n<p>Scroll down to get to the last groups. As we can see, the group \u201cgroupX\u201d is included in the groups list with the Group ID \u201c1024\u201d:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"728\" height=\"433\" class=\"wp-image-22658\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22655-3.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22655-3.png 728w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22655-3-300x178.png 300w\" sizes=\"auto, (max-width: 728px) 100vw, 728px\" \/><\/p>\n<p>Or you can directly list the last set of groups with the \u201ctail\u201d command:<\/p>\n<div class=\"codecolorer-container bash blackboard\" style=\"width:100%;\"><div class=\"bash codecolorer\"><span class=\"kw2\">sudo<\/span> <span class=\"kw2\">tail<\/span> <span class=\"sy0\">\/<\/span>etc<span class=\"sy0\">\/<\/span>group<\/div><\/div>\n<p>The last 10 groups created or added will be displayed including the \u201cgroupX\u201d as well:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"732\" height=\"220\" class=\"wp-image-22659\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22655-4.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22655-4.png 732w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22655-4-300x90.png 300w\" sizes=\"auto, (max-width: 732px) 100vw, 732px\" \/><\/p>\n<h2><strong>Overwriting Already Added Group Using groupadd<\/strong><\/h2>\n<p>The already added group can be overwritten as well using the \u201cgroupadd\u201d command with the \u201c-f\u201d option. The \u201c-f\u201d option overwrites the already existing groups:<\/p>\n<div class=\"codecolorer-container bash blackboard\" style=\"width:100%;\"><div class=\"bash codecolorer\">groupadd <span class=\"re5\">-f<\/span> <span class=\"sy0\">&lt;<\/span>groupName<span class=\"sy0\">&gt;<\/span><\/div><\/div>\n<p>In our case, we already have a \u201cgenz\u201d group as seen by using the \u201ctail\u201d command to list the last set of groups:<\/p>\n<div class=\"codecolorer-container bash blackboard\" style=\"width:100%;\"><div class=\"bash codecolorer\"><span class=\"kw2\">sudo<\/span> <span class=\"kw2\">tail<\/span> <span class=\"sy0\">\/<\/span>etc<span class=\"sy0\">\/<\/span>group<\/div><\/div>\n<p>The \u201cgenz\u201d group already exists with the Group ID of \u201c1005\u201d:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"721\" height=\"219\" class=\"wp-image-22660\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22655-5.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22655-5.png 721w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22655-5-300x91.png 300w\" sizes=\"auto, (max-width: 721px) 100vw, 721px\" \/><\/p>\n<p>Now, If we try to make another group of the same name \u201cgenz\u201d, the command will be:<\/p>\n<div class=\"codecolorer-container bash blackboard\" style=\"width:100%;\"><div class=\"bash codecolorer\"><span class=\"kw2\">sudo<\/span> groupadd genz<\/div><\/div>\n<p>As the group \u201cgenz\u201d already existed and we tried to make another group with the same name, the Terminal warns about the group already existing:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"723\" height=\"57\" class=\"wp-image-22661\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22655-6.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22655-6.png 723w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22655-6-300x24.png 300w\" sizes=\"auto, (max-width: 723px) 100vw, 723px\" \/><\/p>\n<p>To overwrite the existing group, in our case \u201cgenz\u201d, the command is:<\/p>\n<div class=\"codecolorer-container bash blackboard\" style=\"width:100%;\"><div class=\"bash codecolorer\"><span class=\"kw2\">sudo<\/span> groupadd <span class=\"re5\">-f<\/span> genz<\/div><\/div>\n<p>Instead of displaying the \u201cgroup already exists\u201d error, the command line moves to the next line indicating the group was overwritten:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"728\" height=\"73\" class=\"wp-image-22662\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22655-7.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22655-7.png 728w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22655-7-300x30.png 300w\" sizes=\"auto, (max-width: 728px) 100vw, 728px\" \/><\/p>\n<p>To verify, the command \u201csudo tail \/etc\/group\u201d can be used again to list the groups. In our case, the group \u201cgenz\u201d exists means it was overwritten:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"726\" height=\"274\" class=\"wp-image-22663\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22655-8.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22655-8.png 726w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22655-8-300x113.png 300w\" sizes=\"auto, (max-width: 726px) 100vw, 726px\" \/><\/p>\n<h2><strong>Assigning Group ID to the New Group Using groupadd<\/strong><\/h2>\n<p>While creating a new group in Ubuntu, Ubuntu assigns the Group ID to the newly created group by default. The custom group IDs can also be assigned with the \u201cgroupadd\u201d command. The \u201c-g\u201d option with the \u201cgroupadd\u201d command ensures the custom Group ID is to be assigned to the new group having the command:<\/p>\n<div class=\"codecolorer-container bash blackboard\" style=\"width:100%;\"><div class=\"bash codecolorer\">groupadd <span class=\"re5\">-g<\/span> <span class=\"sy0\">&lt;<\/span>groupID<span class=\"sy0\">&gt;<\/span> <span class=\"sy0\">&lt;<\/span>groupName<span class=\"sy0\">&gt;<\/span><\/div><\/div>\n<p>In our case, we have assigned the Group ID \u201c1030\u201d to the new group \u201clinuxWays\u201d with the command:<\/p>\n<div class=\"codecolorer-container bash blackboard\" style=\"width:100%;\"><div class=\"bash codecolorer\"><span class=\"kw2\">sudo<\/span> groupadd <span class=\"re5\">-g<\/span> <span class=\"nu0\">1030<\/span> linuxWays<\/div><\/div>\n<p>The command line moves to the next line indicating the new group \u201clinuxWays\u201d was created:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"731\" height=\"38\" class=\"wp-image-22664\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22655-9.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22655-9.png 731w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22655-9-300x16.png 300w\" sizes=\"auto, (max-width: 731px) 100vw, 731px\" \/><\/p>\n<p>To verify the newly created group, run the \u201ctail\u201d command to list the last set of groups:<\/p>\n<div class=\"codecolorer-container bash blackboard\" style=\"width:100%;\"><div class=\"bash codecolorer\"><span class=\"kw2\">sudo<\/span> <span class=\"kw2\">tail<\/span> <span class=\"sy0\">\/<\/span>etc<span class=\"sy0\">\/<\/span>group<\/div><\/div>\n<p>The group \u201clinuxWays\u201d can be seen in the list with the custom Group ID of \u201c1030\u201d:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"731\" height=\"239\" class=\"wp-image-22665\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22655-10.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22655-10.png 731w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22655-10-300x98.png 300w\" sizes=\"auto, (max-width: 731px) 100vw, 731px\" \/><\/p>\n<h2><strong>Assigning Password to the New Group Using groupadd<\/strong><\/h2>\n<p>While creating a new Group in Ubuntu, Ubuntu does not ask for a password. Adding the password can be useful for enhancing the overall group security. With the \u201c-p\u201d option along with the \u201cgroupadd\u201d command, the password can be assigned to a new group:<\/p>\n<div class=\"codecolorer-container bash blackboard\" style=\"width:100%;\"><div class=\"bash codecolorer\">groupadd <span class=\"re5\">-p<\/span> <span class=\"sy0\">&lt;<\/span>password<span class=\"sy0\">&gt;<\/span> <span class=\"sy0\">&lt;<\/span>groupName<span class=\"sy0\">&gt;<\/span><\/div><\/div>\n<p>In our case, to create a new Group \u201clinuxWays1\u201d with a custom Password, the \u201cgroupadd\u201d command will be:<\/p>\n<div class=\"codecolorer-container bash blackboard\" style=\"width:100%;\"><div class=\"bash codecolorer\"><span class=\"kw2\">sudo<\/span> groupadd <span class=\"re5\">-p<\/span> pass<span class=\"co0\">#1234 linuxWays1<\/span><\/div><\/div>\n<p>The command line moves to the next line indicating the new group was created with a custom password:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"742\" height=\"215\" class=\"wp-image-22666\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22655-11.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22655-11.png 742w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22655-11-300x87.png 300w\" sizes=\"auto, (max-width: 742px) 100vw, 742px\" \/><\/p>\n<p>To verify the creation of the new group, the \u201ctail\u201d command can be used to list the set of last groups added in Ubuntu:<\/p>\n<div class=\"codecolorer-container bash blackboard\" style=\"width:100%;\"><div class=\"bash codecolorer\"><span class=\"kw2\">sudo<\/span> <span class=\"kw2\">tail<\/span> <span class=\"sy0\">\/<\/span>etc<span class=\"sy0\">\/<\/span>group<\/div><\/div>\n<p>As seen in the Terminal, the \u201clinuxWays1\u201d group is created and added to Ubuntu:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"732\" height=\"333\" class=\"wp-image-22667\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22655-12.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22655-12.png 732w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22655-12-300x136.png 300w\" sizes=\"auto, (max-width: 732px) 100vw, 732px\" \/><\/p>\n<h2><strong>Creating a New Group With Custom Values Using groupadd<\/strong><\/h2>\n<p>Ubuntu, while adding and creating a new group, assigns the default values to the Group. The \u201c-K\u201d option along with the \u201cgroupadd\u201d command ensures the group will be added with the given custom values:<\/p>\n<div class=\"codecolorer-container bash blackboard\" style=\"width:100%;\"><div class=\"bash codecolorer\">groupadd <span class=\"re5\">-K<\/span> <span class=\"sy0\">&lt;<\/span>customValue<span class=\"sy0\">&gt;<\/span> <span class=\"sy0\">&lt;<\/span>groupName<span class=\"sy0\">&gt;<\/span><\/div><\/div>\n<p>In our case, to add the group \u201cgenX\u201d with the custom values of \u201cGID_MIN\u201d and \u201cGID_MAX\u201d, the \u201cgroupadd\u201d command is:<\/p>\n<div class=\"codecolorer-container bash blackboard\" style=\"width:100%;\"><div class=\"bash codecolorer\"><span class=\"kw2\">sudo<\/span> groupadd <span class=\"re5\">-K<\/span> <span class=\"re2\">GID_MIN<\/span>=<span class=\"nu0\">1050<\/span> <span class=\"re5\">-K<\/span> <span class=\"re2\">GID_MAX<\/span>=<span class=\"nu0\">1500<\/span> genX<\/div><\/div>\n<p>The \u201cGID_MIN=1050\u201d and \u201cGID_MAX=1500\u201d mean the Group ID assigned should be between \u201c1050\u201d and \u201c1500\u201d. The cursor moves to the next line once the group is added:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"732\" height=\"57\" class=\"wp-image-22668\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22655-13.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22655-13.png 732w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22655-13-300x23.png 300w\" sizes=\"auto, (max-width: 732px) 100vw, 732px\" \/><\/p>\n<p>To verify the addition of the group \u201cgenX\u201d, the \u201ctail\u201d command is used:<\/p>\n<div class=\"codecolorer-container bash blackboard\" style=\"width:100%;\"><div class=\"bash codecolorer\"><span class=\"kw2\">sudo<\/span> <span class=\"kw2\">tail<\/span> <span class=\"sy0\">\/<\/span>etc<span class=\"sy0\">\/<\/span>group<\/div><\/div>\n<p>Instead of Ubuntu giving the group \u201cgenX\u201d a Group ID of \u201c1032\u201d, a custom Group ID is assigned:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"725\" height=\"221\" class=\"wp-image-22669\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22655-14.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22655-14.png 725w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22655-14-300x91.png 300w\" sizes=\"auto, (max-width: 725px) 100vw, 725px\" \/><\/p>\n<h2><strong>Adding New User to a Group Using groupadd<\/strong><\/h2>\n<p>The \u201cuseradd\u201d command is used to create a new user in Ubuntu. By default, the new user is assigned to a group of its own, i.e. the newly created user has its own group. Now to assign the new user to a specific group, the \u201c-g\u201d flag with the \u201cuseradd\u201d command is used:<\/p>\n<div class=\"codecolorer-container bash blackboard\" style=\"width:100%;\"><div class=\"bash codecolorer\">useradd <span class=\"re5\">-g<\/span> <span class=\"sy0\">&lt;<\/span>groupName<span class=\"sy0\">&gt;<\/span> <span class=\"sy0\">&lt;<\/span>userName<span class=\"sy0\">&gt;<\/span><\/div><\/div>\n<p>In our case, to assign the new user \u201cmicheal\u201d to the group \u201cgenX\u201d, the \u201cuseradd\u201d command will be:<\/p>\n<div class=\"codecolorer-container bash blackboard\" style=\"width:100%;\"><div class=\"bash codecolorer\"><span class=\"kw2\">sudo<\/span> useradd <span class=\"re5\">-g<\/span> genX micheal<\/div><\/div>\n<p>The Terminal cursor moves to the next line which means the new user was added to the group \u201cgenX\u201d:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"726\" height=\"40\" class=\"wp-image-22670\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22655-15.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22655-15.png 726w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22655-15-300x17.png 300w\" sizes=\"auto, (max-width: 726px) 100vw, 726px\" \/><\/p>\n<p>To verify if the new user \u201cmicheal\u201d was added to the group \u201cgenX\u201d, the command used will be:<\/p>\n<div class=\"codecolorer-container bash blackboard\" style=\"width:100%;\"><div class=\"bash codecolorer\"><span class=\"kw2\">sudo<\/span> <span class=\"sy0\">\/<\/span>etc<span class=\"sy0\">\/<\/span><span class=\"kw2\">passwd<\/span><\/div><\/div>\n<p>This will list all the users of Ubuntu with their details. As the new user \u201cmicheal\u201d was added to the group \u201cgenX\u201d, we can see that the user \u201cmicheal\u201d has the group ID of 1050 which is the Group ID of \u201cgenX\u201d:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"726\" height=\"221\" class=\"wp-image-22671\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22655-16.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22655-16.png 726w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22655-16-300x91.png 300w\" sizes=\"auto, (max-width: 726px) 100vw, 726px\" \/><\/p>\n<h2><strong>Adding Existing User to a Group Using groupadd<\/strong><\/h2>\n<p>An existing user can also be added to a group. To add an existing user to a specific group, the \u201cusermod\u201d command is used with the syntax:<\/p>\n<div class=\"codecolorer-container bash blackboard\" style=\"width:100%;\"><div class=\"bash codecolorer\">usermod <span class=\"re5\">-g<\/span> <span class=\"sy0\">&lt;<\/span>groupName<span class=\"sy0\">&gt;<\/span> <span class=\"sy0\">&lt;<\/span>existingUserName<span class=\"sy0\">&gt;<\/span><\/div><\/div>\n<p>In our case, the user \u201caswan\u201d is added by default to group 1022 which is \u201caswan\u201d, and can be verified using the \u201ctail\u201d command:<\/p>\n<div class=\"codecolorer-container bash blackboard\" style=\"width:100%;\"><div class=\"bash codecolorer\"><span class=\"kw2\">sudo<\/span> <span class=\"kw2\">tail<\/span> <span class=\"sy0\">\/<\/span>etc<span class=\"sy0\">\/<\/span><span class=\"kw2\">passwd<\/span><\/div><\/div>\n<p>The user \u201caswan\u201d as seen below, has a group ID of 1022:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"728\" height=\"214\" class=\"wp-image-22672\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22655-17.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22655-17.png 728w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22655-17-300x88.png 300w\" sizes=\"auto, (max-width: 728px) 100vw, 728px\" \/><\/p>\n<p>Now to assign or add \u201caswan\u201d to another group, in our case adding to the group \u201clinuxWays\u201d, the \u201cusermod\u201d command is:<\/p>\n<div class=\"codecolorer-container bash blackboard\" style=\"width:100%;\"><div class=\"bash codecolorer\"><span class=\"kw2\">sudo<\/span> usermod <span class=\"re5\">-g<\/span> linuxWays aswan<\/div><\/div>\n<p>The \u201c-g\u201d option ensures adding the user to a group:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"728\" height=\"41\" class=\"wp-image-22673\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22655-18.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22655-18.png 728w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22655-18-300x17.png 300w\" sizes=\"auto, (max-width: 728px) 100vw, 728px\" \/><\/p>\n<p>To verify if the user \u201caswan\u201d was added to the group \u201clinuxWays\u201d, the \u201ctail\u201d command is used:<\/p>\n<div class=\"codecolorer-container bash blackboard\" style=\"width:100%;\"><div class=\"bash codecolorer\"><span class=\"kw2\">sudo<\/span> <span class=\"kw2\">tail<\/span> <span class=\"sy0\">\/<\/span>etc<span class=\"sy0\">\/<\/span><span class=\"kw2\">passwd<\/span><\/div><\/div>\n<p>As we can see, the user \u201caswan\u201d had the Group ID \u201c1022\u201d before, and now the GID changed to \u201c1030\u201d indicating the group of user \u201caswan\u201d has changed:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"725\" height=\"221\" class=\"wp-image-22674\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22655-19.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22655-19.png 725w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22655-19-300x91.png 300w\" sizes=\"auto, (max-width: 725px) 100vw, 725px\" \/><\/p>\n<p>That\u2019s all about creating groups in Linux using the groupadd command.<\/p>\n<h2><strong>Conclusion<\/strong><\/h2>\n<p>The \u201cgroupadd\u201d command is useful for creating user groups with default configuration, custom configuration, custom GID, and can also be used to set passwords to a group in Ubuntu. This article discussed all the methods in which the \u201cgroupadd\u201d command can be used.<\/p>","protected":false},"excerpt":{"rendered":"<p>The \u201cgroupadd\u201d command is useful in creating user groups with default configuration, custom configuration, custom GID, and can also be used to set passwords.<\/p>","protected":false},"author":110,"featured_media":22676,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1049],"tags":[],"class_list":["post-22655","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-linux-commands"],"_links":{"self":[{"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/posts\/22655","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/users\/110"}],"replies":[{"embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/comments?post=22655"}],"version-history":[{"count":0,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/posts\/22655\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/media\/22676"}],"wp:attachment":[{"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/media?parent=22655"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/categories?post=22655"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/tags?post=22655"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}