{"id":624,"date":"2011-03-20T10:49:39","date_gmt":"2011-03-20T02:49:39","guid":{"rendered":"https:\/\/webhostinggeeks.com\/howto\/?p=624"},"modified":"2023-04-28T09:50:36","modified_gmt":"2023-04-28T09:50:36","slug":"how-to-add-user-into-group-in-linux","status":"publish","type":"post","link":"https:\/\/webhostinggeeks.com\/howto\/how-to-add-user-into-group-in-linux\/","title":{"rendered":"How to Add User into Group in Linux"},"content":{"rendered":"<p>There are two ways to add user into existing group which are useradd and usermod. The <strong>useradd<\/strong> command is to create a new user or update default new user information. Meanwhile the <strong>usermod<\/strong> command is to modify a user account i.e. it is useful to add existing user to existing group.<\/p>\n<p>In Linux, there are two types of group that we can specify which are primary and secondary.\u00a0 Primary group is the default group of the user and the group name should equal as the username. If the username is demoroot, then the primary group should be demoroot as well.<\/p>\n<ol>\n<pre class=\"code\">[root@server ~]# useradd demoroot\n[root@server ~]# grep demoroot \/etc\/group\ndemoroot:x:503:\n<\/pre>\n<\/ol>\n<p>And the secondary group is the second group of the user that we can add either using <strong>useradd<\/strong> or <strong>usermod<\/strong> . All user account related information is stored in <strong>\/etc\/passwd<\/strong>, <strong>\/etc\/shadow<\/strong> and <strong>\/etc\/group<\/strong> files to store user information.<\/p>\n<p>1. Add existing user (demoroot) into root group. As state above, the group for demoroot user is only as below :<\/p>\n<ol>\n<pre class=\"code\">demoroot:x:503:\n<\/pre>\n<\/ol>\n<ol>\n<pre class=\"code\">[root@server ~]# usermod -G root demoroot\n[root@server ~]# grep demoroot \/etc\/group\nroot:x:0:root,demoroot\ndemoroot:x:503:\n<\/pre>\n<\/ol>\n<p>This <strong>usermod<\/strong> command with -G option modify a demoroot account, and add demoroot into existing root group.<\/p>\n<p>2. Add new user into Existing group.<\/p>\n<ol>\n<pre class=\"code\">[root@server ~]# useradd -G root testroot\n[root@server ~]# grep testroot \/etc\/group\nroot:x:0:root,demoroot,testroot\ntestroot:x:504:\n<\/pre>\n<\/ol>\n<p>This <strong>useradd<\/strong> command with -G option has created a new user, then add into existing root group<\/p>\n<ol>\n<pre class=\"code\">\n[root@server ~]# grep root \/etc\/group\nroot:x:0:root,demoroot,testroot\nbin:x:1:root,bin,daemon\ndaemon:x:2:root,bin,daemon\nsys:x:3:root,bin,adm\nadm:x:4:root,adm,daemon\ndisk:x:6:root\nwheel:x:10:root\ndemoroot:x:503:\ntestroot:x:504:\n<\/pre>\n<\/ol>\n","protected":false},"excerpt":{"rendered":"<p>There are two ways to add user into existing group which are useradd and usermod. The useradd command is to create a new user or update default new user information&#8230;.<\/p>\n","protected":false},"author":6,"featured_media":323,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"wds_primary_category":0,"footnotes":""},"categories":[996],"tags":[1536],"class_list":["post-624","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-linux","tag-linux"],"_links":{"self":[{"href":"https:\/\/webhostinggeeks.com\/howto\/wp-json\/wp\/v2\/posts\/624","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/webhostinggeeks.com\/howto\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/webhostinggeeks.com\/howto\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/webhostinggeeks.com\/howto\/wp-json\/wp\/v2\/users\/6"}],"replies":[{"embeddable":true,"href":"https:\/\/webhostinggeeks.com\/howto\/wp-json\/wp\/v2\/comments?post=624"}],"version-history":[{"count":0,"href":"https:\/\/webhostinggeeks.com\/howto\/wp-json\/wp\/v2\/posts\/624\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/webhostinggeeks.com\/howto\/wp-json\/wp\/v2\/media\/323"}],"wp:attachment":[{"href":"https:\/\/webhostinggeeks.com\/howto\/wp-json\/wp\/v2\/media?parent=624"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/webhostinggeeks.com\/howto\/wp-json\/wp\/v2\/categories?post=624"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/webhostinggeeks.com\/howto\/wp-json\/wp\/v2\/tags?post=624"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}