{"id":1626,"date":"2021-06-04T14:51:50","date_gmt":"2021-06-04T14:51:50","guid":{"rendered":"https:\/\/codeinsightacademy.com\/blog\/?p=1626"},"modified":"2024-05-06T08:50:26","modified_gmt":"2024-05-06T08:50:26","slug":"user-group-and-permission","status":"publish","type":"post","link":"https:\/\/codeinsightacademy.com\/blog\/linux\/user-group-and-permission\/","title":{"rendered":"User Group and Permission"},"content":{"rendered":"\n<h2 class=\"has-text-align-center\"><strong>User<\/strong><\/h2>\n\n\n\n<p>List all users<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>cat \/etc\/passwd<\/code><\/pre>\n\n\n\n<p>List specific user<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>cat \/etc\/passwd | grep username\nOR\ngrep username \/etc\/passwd<\/code><\/pre>\n\n\n\n<p>Create new user<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>useradd username<\/code><\/pre>\n\n\n\n<p>Delete existing user<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>userdel username<\/code><\/pre>\n\n\n\n<p>Set user password or update password<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>passwd username<\/code><\/pre>\n\n\n\n<p>You can use shortcut to add new user. Using following command you can create user set password and create home directory for newly added user<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>adduser username\nls -l \/home\/username<\/code><\/pre>\n\n\n\n<p>Rename existing user<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>usermod --login new-name old-name<\/code><\/pre>\n\n\n\n<h2 class=\"has-text-align-center\"><strong>Group<\/strong><\/h2>\n\n\n\n<p>List all groups<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>cat \/etc\/group<\/code><\/pre>\n\n\n\n<p>List specific group<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>cat \/etc\/group | grep groupname\ncat \/etc\/group | grep ^groupname\ngrep groupname \/etc\/group\ngrep ^groupname \/etc\/group<\/code><\/pre>\n\n\n\n<p>Add new group<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>groupadd group-name<\/code><\/pre>\n\n\n\n<p>Delete existing group<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>groupdel group-name<\/code><\/pre>\n\n\n\n<p>List all members of specific group<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>getent group group-name<\/code><\/pre>\n\n\n\n<p>Add new member in specific groups<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>usermod -a -G group-name1,group-name2,... user-name<\/code><\/pre>\n\n\n\n<p>Check in which groups user exist<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>groups user-name<\/code><\/pre>\n\n\n\n<p>Remove user from specific group<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>gpasswd -d user-name group-name<\/code><\/pre>\n\n\n\n<h2 class=\"has-text-align-center\">Permission<\/h2>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large\"><a href=\"https:\/\/codeinsightacademy.com\/blog\/http:\/\/codeinsightacademy.com\/blog\/wp-content\/uploads\/2021\/06\/owner-3.png\"><img loading=\"lazy\" width=\"435\" height=\"79\" src=\"https:\/\/codeinsightacademy.com\/blog\/http:\/\/codeinsightacademy.com\/blog\/wp-content\/uploads\/2021\/06\/owner-3.png\" alt=\"\" class=\"wp-image-1646\" srcset=\"https:\/\/codeinsightacademy.com\/blog\/http:\/\/codeinsightacademy.com\/blog\/wp-content\/uploads\/2021\/06\/owner-3.png 435w, https:\/\/codeinsightacademy.com\/blog\/http:\/\/codeinsightacademy.com\/blog\/wp-content\/uploads\/2021\/06\/owner-3-300x54.png 300w\" sizes=\"(max-width: 435px) 100vw, 435px\" \/><\/a><figcaption>LIST FILES AND DIRECTORIES<\/figcaption><\/figure><\/div>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large\"><a href=\"https:\/\/codeinsightacademy.com\/blog\/http:\/\/codeinsightacademy.com\/blog\/wp-content\/uploads\/2021\/06\/owner.png\"><img loading=\"lazy\" width=\"435\" height=\"79\" src=\"https:\/\/codeinsightacademy.com\/blog\/http:\/\/codeinsightacademy.com\/blog\/wp-content\/uploads\/2021\/06\/owner.png\" alt=\"\" class=\"wp-image-1642\" srcset=\"https:\/\/codeinsightacademy.com\/blog\/http:\/\/codeinsightacademy.com\/blog\/wp-content\/uploads\/2021\/06\/owner.png 435w, https:\/\/codeinsightacademy.com\/blog\/http:\/\/codeinsightacademy.com\/blog\/wp-content\/uploads\/2021\/06\/owner-300x54.png 300w\" sizes=\"(max-width: 435px) 100vw, 435px\" \/><\/a><figcaption>OWNER &#8211; FIRST 3 FLAGS SHOWS OWNER&#8217;S PERMISSION<\/figcaption><\/figure><\/div>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large\"><a href=\"https:\/\/codeinsightacademy.com\/blog\/http:\/\/codeinsightacademy.com\/blog\/wp-content\/uploads\/2021\/06\/owner-1.png\"><img loading=\"lazy\" width=\"435\" height=\"79\" src=\"https:\/\/codeinsightacademy.com\/blog\/http:\/\/codeinsightacademy.com\/blog\/wp-content\/uploads\/2021\/06\/owner-1.png\" alt=\"\" class=\"wp-image-1644\" srcset=\"https:\/\/codeinsightacademy.com\/blog\/http:\/\/codeinsightacademy.com\/blog\/wp-content\/uploads\/2021\/06\/owner-1.png 435w, https:\/\/codeinsightacademy.com\/blog\/http:\/\/codeinsightacademy.com\/blog\/wp-content\/uploads\/2021\/06\/owner-1-300x54.png 300w\" sizes=\"(max-width: 435px) 100vw, 435px\" \/><\/a><figcaption>GROUP- MIDDLE 3 FLAGS SHOWS GROUP&#8217;S PERMISSION<\/figcaption><\/figure><\/div>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large\"><a href=\"https:\/\/codeinsightacademy.com\/blog\/http:\/\/codeinsightacademy.com\/blog\/wp-content\/uploads\/2021\/06\/owner-2.png\"><img loading=\"lazy\" width=\"435\" height=\"79\" src=\"https:\/\/codeinsightacademy.com\/blog\/http:\/\/codeinsightacademy.com\/blog\/wp-content\/uploads\/2021\/06\/owner-2.png\" alt=\"\" class=\"wp-image-1645\" srcset=\"https:\/\/codeinsightacademy.com\/blog\/http:\/\/codeinsightacademy.com\/blog\/wp-content\/uploads\/2021\/06\/owner-2.png 435w, https:\/\/codeinsightacademy.com\/blog\/http:\/\/codeinsightacademy.com\/blog\/wp-content\/uploads\/2021\/06\/owner-2-300x54.png 300w\" sizes=\"(max-width: 435px) 100vw, 435px\" \/><\/a><figcaption>OTHERS- LAST 3 FLAGS SHOWS OTHER&#8217;S PERMISSION<\/figcaption><\/figure><\/div>\n\n\n\n<p>Permission List<\/p>\n\n\n\n<ul><li>7 &#8211; 111 =&gt; read write execute<\/li><li>6 &#8211; 110 =&gt; read write &#8211;<\/li><li>5 &#8211; 101 =&gt; read &#8211; execute<\/li><li>4 &#8211; 100 =&gt; read &#8211; &#8211;<\/li><li>3 &#8211; 011 =&gt; &#8211; write execute<\/li><li>2 &#8211; 010 =&gt; &#8211; write &#8211;<\/li><li>1 &#8211; 001 =&gt; &#8211; &#8211; execute<\/li><li>0 &#8211; 000 =&gt; no permission<\/li><\/ul>\n\n\n\n<p>How to change permission<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>chmod -Rf 777 path-to-file-or-directory<\/code><\/pre>\n\n\n\n<p>How to give only specific permission<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>#only executable\nchmod -Rf +x path-to-file-or-directory\n\n#only writable\nchmod -Rf +w path-to-file-or-directory\n\n#only readable\nchmod -Rf +r path-to-file-or-directory<\/code><\/pre>\n\n\n\n<p>How to give permission to only specific role<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>#only owner\nchmod -Rf u+x path-to-file-or-directory\n\n#only group\nchmod -Rf g+x path-to-file-or-directory\n\n#only others\nchmod -Rf o+x path-to-file-or-directory\n<\/code><\/pre>\n\n\n\n<h2 class=\"has-text-align-center\">Ownership<\/h2>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large\"><a href=\"https:\/\/codeinsightacademy.com\/blog\/http:\/\/codeinsightacademy.com\/blog\/wp-content\/uploads\/2021\/06\/owner-4.png\"><img loading=\"lazy\" width=\"435\" height=\"79\" src=\"https:\/\/codeinsightacademy.com\/blog\/http:\/\/codeinsightacademy.com\/blog\/wp-content\/uploads\/2021\/06\/owner-4.png\" alt=\"\" class=\"wp-image-1660\" srcset=\"https:\/\/codeinsightacademy.com\/blog\/http:\/\/codeinsightacademy.com\/blog\/wp-content\/uploads\/2021\/06\/owner-4.png 435w, https:\/\/codeinsightacademy.com\/blog\/http:\/\/codeinsightacademy.com\/blog\/wp-content\/uploads\/2021\/06\/owner-4-300x54.png 300w\" sizes=\"(max-width: 435px) 100vw, 435px\" \/><\/a><figcaption>FIRST FLAG IN ROLE IS FOR OWNER<\/figcaption><\/figure><\/div>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large\"><a href=\"https:\/\/codeinsightacademy.com\/blog\/http:\/\/codeinsightacademy.com\/blog\/wp-content\/uploads\/2021\/06\/owner-5.png\"><img loading=\"lazy\" width=\"435\" height=\"79\" src=\"https:\/\/codeinsightacademy.com\/blog\/http:\/\/codeinsightacademy.com\/blog\/wp-content\/uploads\/2021\/06\/owner-5.png\" alt=\"\" class=\"wp-image-1661\" srcset=\"https:\/\/codeinsightacademy.com\/blog\/http:\/\/codeinsightacademy.com\/blog\/wp-content\/uploads\/2021\/06\/owner-5.png 435w, https:\/\/codeinsightacademy.com\/blog\/http:\/\/codeinsightacademy.com\/blog\/wp-content\/uploads\/2021\/06\/owner-5-300x54.png 300w\" sizes=\"(max-width: 435px) 100vw, 435px\" \/><\/a><figcaption>SECOND FLAG IN ROLE IS FOR GROUP<\/figcaption><\/figure><\/div>\n\n\n\n<p>How to change ownership of any file or directory<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>chown -Rf user:group path-to-file-or-directory<\/code><\/pre>\n\n\n\n<p>Change attribute read only<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>chattr +a file.txt<\/code><\/pre>\n\n\n\n<ul><li><code>chattr<\/code>: This is a command in Linux used to change file attributes on a file system.<\/li><li><code>+a<\/code>: This option sets the &#8220;append-only&#8221; attribute on the specified file. When this attribute is set, the file can only be opened in append mode for writing. Existing data in the file cannot be modified or removed. This attribute is often used to prevent accidental deletion or modification of important files.<\/li><li>to revert use -a option for chattr<\/li><\/ul>\n\n\n\n<figure class=\"wp-block-embed is-type-video is-provider-youtube wp-block-embed-youtube wp-embed-aspect-16-9 wp-has-aspect-ratio\"><div class=\"wp-block-embed__wrapper\">\n<iframe loading=\"lazy\" title=\"#3 Linux - User Group Permission\" width=\"640\" height=\"360\" src=\"https:\/\/www.youtube.com\/embed\/MQHOn9JbEOk?feature=oembed\" frameborder=\"0\" allow=\"accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share\" referrerpolicy=\"strict-origin-when-cross-origin\" allowfullscreen><\/iframe>\n<\/div><\/figure>\n","protected":false},"excerpt":{"rendered":"<p>User List all users List specific user Create new user Delete existing user Set user password or update password You can use shortcut to add new user. Using following command you can create user set password and create home directory for newly added user Rename existing user Group List all groups List specific group Add [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[31],"tags":[],"_links":{"self":[{"href":"https:\/\/codeinsightacademy.com\/blog\/wp-json\/wp\/v2\/posts\/1626"}],"collection":[{"href":"https:\/\/codeinsightacademy.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/codeinsightacademy.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/codeinsightacademy.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/codeinsightacademy.com\/blog\/wp-json\/wp\/v2\/comments?post=1626"}],"version-history":[{"count":20,"href":"https:\/\/codeinsightacademy.com\/blog\/wp-json\/wp\/v2\/posts\/1626\/revisions"}],"predecessor-version":[{"id":2713,"href":"https:\/\/codeinsightacademy.com\/blog\/wp-json\/wp\/v2\/posts\/1626\/revisions\/2713"}],"wp:attachment":[{"href":"https:\/\/codeinsightacademy.com\/blog\/wp-json\/wp\/v2\/media?parent=1626"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/codeinsightacademy.com\/blog\/wp-json\/wp\/v2\/categories?post=1626"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/codeinsightacademy.com\/blog\/wp-json\/wp\/v2\/tags?post=1626"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}