

{"id":109693,"date":"2022-06-14T09:00:51","date_gmt":"2022-06-14T03:30:51","guid":{"rendered":"https:\/\/data-flair.training\/blogs\/?p=109693"},"modified":"2022-06-14T09:57:21","modified_gmt":"2022-06-14T04:27:21","slug":"chmod-in-linux","status":"publish","type":"post","link":"https:\/\/data-flair.training\/blogs\/chmod-in-linux\/","title":{"rendered":"Chmod in Linux"},"content":{"rendered":"<p>In this article, you will learn what Linuchmod is and its use, and understand the different file permissions. We will also see the syntax of the chmod command and the options used along with it. We shall also see how to change the file permissions and modify them accordingly.<\/p>\n<h3>What is chmod in Linux?<\/h3>\n<p>In UNIX-like operating systems, there is a set of instructions or in Linux language &#8211; \u201cflags\u201d. These flags are associated with each file and determine who can open them and how can they access them. These flags are called \u2018modes\u2019 or \u2018permissions\u2019<\/p>\n<p>Chmod is the abbreviation for Change Mode. it is a command which allows you to change the access permissions of files and directories.<\/p>\n<p>In fact, if you run the command: \u201cls -l\u201d in the terminal you get this output:<\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2022\/05\/ls-l.webp\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-109727\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2022\/05\/ls-l.webp\" alt=\"ls l\" width=\"1086\" height=\"295\" \/><\/a><\/p>\n<p>So when we list the contents of the desktop directory, you can see a prefix to each of the content there in the form of \u201c-rw-rw-r&#8211;\u201d, these are the file permissions that determine who can open and how can they access them.<\/p>\n<h3>Why use Linux chmod?<\/h3>\n<p>With chmod, you have the freedom to authorize users according to your needs. You are the master of everything, you can be specific as to who reads, writes, or executes the files. In a nutshell, you can change the access permissions of a file system as per your liking.<\/p>\n<h3>Understanding file permissions<\/h3>\n<p>Before we even touch on the syntax and options related to chmod, let us get a better understanding of the permission of a file system.<\/p>\n<p>Let us take the above file permissions: \u201c-rw-rw-r&#8211;\u201d. On closer observation, we can see that this file permission is a combination of 3 specific sets of instructions as follows: \u201drw\u201d, \u201crw\u201d and \u201cr&#8211;\u201d. The first hyphen also gives us information regarding the file type, however, the subsequent hyphens simply act as null values (as in there is no permission).<\/p>\n<p>Before we even look into what \u2018r\u2019 and \u2018w\u2019 are, let us see what these 3 sets of permission do. The 1st set of permissions is for the user, the 2nd set is for the group and the 3rd set is for others. Let us look into each of these.<\/p>\n<h4>User<\/h4>\n<p>The user is the owner of the file. By default, the person who creates the file or directory becomes the owner. Therefore a user is also called the owner.<\/p>\n<h4>Group<\/h4>\n<p>A group can contain multiple users. Say you have a project and a number of people need access to a file. Instead of individually assigning permissions to each of them, you can simply add all the users in a group and assign group permissions.<\/p>\n<h4>Other<\/h4>\n<p>As the name suggests, it is for any other user who has access to the file. This user has nighter created a file, nor do they belong to a group. So basically, when you set the other permissions, it applies to the rest of the world.<\/p>\n<p>Now there is 1 minuscule topic left before we look at what \u2018r\u2019 and \u2018w\u2019 are. What does the first hyphen represent?<\/p>\n<p>If you look carefully at the contents of the desktop directory, the directories \u201cmovies\u201d and \u201cother\u201d have the same set of permissions, except for one difference: \u201cdrwxrwxr-x\u201d, the first hyphen was replaced with a d, indicating it is a directory and not a file: here is what each file type is denoted by:<\/p>\n<ul>\n<li>d = Directory<\/li>\n<li>&#8211; = Regular file<\/li>\n<li>l = Symbolic link<\/li>\n<\/ul>\n<p>Now that we know what each set of permissions is for, let us now understand the terminology and how to use \u2018r\u2019, \u2018w\u2019, and \u2018x\u2019<\/p>\n<p>As we say the first character represents the type of file. The remaining 9 bits in groups of 3 represent permissions for the user, group, and global. Each of the bits stands for:<\/p>\n<ul>\n<li>r = Read<\/li>\n<li>w = Write<\/li>\n<li>x = Execute<\/li>\n<li>&#8211; = No permission (no value)<\/li>\n<\/ul>\n<p>Let us look into a few examples before proceeding further.<\/p>\n<p><strong>a. \u201c-rwxrwxrwx\u201d<\/strong><\/p>\n<p>This permission is for a regular file and the user, group, and others can read, write and execute it.<\/p>\n<p><strong>b. \u201cdr-xr-xr-x\u201d<\/strong><\/p>\n<p>This permission is for a directory and the user, group, and others can only read and execute it.<\/p>\n<p><strong>c. \u201c-rwxrwxr-x\u201d<\/strong><\/p>\n<p>This permission is for a regular file and the user and user group can read, write and execute but others can only read and execute it.<\/p>\n<p><strong>d. \u201c-rwx-r-x&#8212;\u201d<\/strong><\/p>\n<p>This permission is for a regular file and the user can read, write and execute, the user group can only read and execute, whereas others have no permissions at all.<\/p>\n<p>Now that we have understood the permissions, let is try to analyze the permission for a file in the desktop: \u201c-rw-rw-r&#8211;\u201d. These permission are for a regular file and the user and user group can read and write but not execute, and others can only read the file.<\/p>\n<h4>Octal notation of permission<\/h4>\n<p>Before we see the syntax and option, it is important to denote the permissions in the form of binary and octal forms. This will prove to be helpful while changing file permissions using the chmod command.<\/p>\n<p>This way of representation is called octal notation because the binary numbers are converted to base &#8211; 8 by using the digits 0 to 7:<\/p>\n<table>\n<tbody>\n<tr>\n<td><span style=\"font-weight: 400;\">Binary Notation<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Octal Notation<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Permission<\/span><\/td>\n<td><span style=\"font-weight: 400;\">meaning<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">000<\/span><\/td>\n<td><span style=\"font-weight: 400;\">0<\/span><\/td>\n<td><span style=\"font-weight: 400;\">&#8211;<\/span><\/td>\n<td><span style=\"font-weight: 400;\">No permission<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">001<\/span><\/td>\n<td><span style=\"font-weight: 400;\">1<\/span><\/td>\n<td><span style=\"font-weight: 400;\">&#8211;x<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Only execute<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">010<\/span><\/td>\n<td><span style=\"font-weight: 400;\">2<\/span><\/td>\n<td><span style=\"font-weight: 400;\">-w-<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Only write<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">011<\/span><\/td>\n<td><span style=\"font-weight: 400;\">3<\/span><\/td>\n<td><span style=\"font-weight: 400;\">-wx<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Write and execute<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">100<\/span><\/td>\n<td><span style=\"font-weight: 400;\">4<\/span><\/td>\n<td><span style=\"font-weight: 400;\">r&#8211;<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Only read<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">101<\/span><\/td>\n<td><span style=\"font-weight: 400;\">5<\/span><\/td>\n<td><span style=\"font-weight: 400;\">r-x<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Read and execute<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">110<\/span><\/td>\n<td><span style=\"font-weight: 400;\">6<\/span><\/td>\n<td><span style=\"font-weight: 400;\">rw-<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Read and write<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">111<\/span><\/td>\n<td><span style=\"font-weight: 400;\">7<\/span><\/td>\n<td><span style=\"font-weight: 400;\">rwx<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Read write and execute<\/span><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>Let us look at a few examples using octal notations:<\/p>\n<p><strong>a. 705<\/strong><\/p>\n<p>705 stands for \u201crwx&#8212;r-x\u201d. This means that the user can read write and execute, the user group has no instructions whatsoever and others can only read and execute.<\/p>\n<p><strong>b. 635<\/strong><\/p>\n<p>635 stands for \u201crw&#8211;wxr-x\u201d. This means that the user can read and write, the user group can write and execute and the others can read and execute.<\/p>\n<p><strong>c. 721<\/strong><\/p>\n<p>721 stands for \u201crwx-w&#8212;x\u201d. This means that the user can read write and execute, the user group can only write and other can only execute the file.<\/p>\n<h3>How to use chmod command?<\/h3>\n<p>Now that we are clear with the permission, let us see how to use the chmod command to tinker with the permissions.<\/p>\n<p>Let us start with the basics by understanding the syntax. The syntax for chmod is :<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">chmod &lt;options&gt; &lt;permissions&gt; &lt;filename&gt;<\/pre>\n<p>This is the most basic way of writing chmod commands, you can play with this command by using different things by using the syntax:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">chmod &lt;options&gt; &lt;u,g,o,a&gt;&lt;-,+, =&gt;&lt;permissions&gt;&lt;filename&gt;<\/pre>\n<p>First let us look at the fields where we enter u, g, o, a and -, +, =, before we look at the options used with chmod.<\/p>\n<p>The flags \u201cu, g, o, a\u201d define which users classes the permission to the files are changed.<\/p>\n<ul>\n<li>u &#8211; represents the owner\/user<\/li>\n<li>g &#8211; represents the user group<\/li>\n<li>o &#8211; represents all the other users (rest of the world)<\/li>\n<li>a &#8211; represents all the users: user + group + other users (same as ugo)<\/li>\n<\/ul>\n<p>If this flag is omitted, the default value will be taken as \u2018a\u2019<\/p>\n<p>The set of flags which deal with \u201c-, +, =\u201d defines the permissions to be removed or added.<\/p>\n<ul>\n<li>The + means Add the permissions<\/li>\n<li>&#8211; means Removes the permissions<\/li>\n<li>= means Changes the current permissions to the specified permissions.<\/li>\n<\/ul>\n<p>Let us look at some examples using the \u201cu, g, o, a\u201d and the \u201c-, +, =\u201d flags (yes, we don\u2019t need options just yet!)<\/p>\n<p><strong>a. \u201crwxrwxrwx\u201d<\/strong><\/p>\n<p>To give the permissions of reading, writing and executing to all the users, we can use the octal notation and simply write:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">chmod 777 &lt;filename&gt;<\/pre>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2022\/05\/octal-777.webp\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-109733\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2022\/05\/octal-777.webp\" alt=\"octal 777\" width=\"880\" height=\"256\" \/><\/a><\/p>\n<p>Or using the flags we just discussed you can write:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">chmod u=rwx, g=rwx, u=rwx &lt;filename&gt;<\/pre>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2022\/05\/permission-using-flag.webp\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-109734\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2022\/05\/permission-using-flag.webp\" alt=\"permission using flag\" width=\"780\" height=\"181\" \/><\/a><\/p>\n<p>You can also write:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">chmod a=rwx &lt;filename&gt;<\/pre>\n<p>As \u2018a\u2019 is the same as \u2018ugo\u2019<\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2022\/05\/ugo.webp\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-109735\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2022\/05\/ugo.webp\" alt=\"ugo\" width=\"694\" height=\"189\" \/><\/a><\/p>\n<p><strong>b. \u201crw&#8212;&#8212;-\u201d<\/strong><\/p>\n<p>To give only the user the permissions to read, write and execute, you can simply use the octal notation and write:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">chmod 600 &lt;filename&gt;<\/pre>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2022\/05\/octal600.webp\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-109736\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2022\/05\/octal600.webp\" alt=\"octal 600\" width=\"664\" height=\"191\" \/><\/a><\/p>\n<p>Or you can use the flags \u201cu, g, o, a\u201d and write:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">chmod u = rw, g= , o= &lt;filename&gt;<\/pre>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2022\/05\/permission-to-user-only.webp\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-109737\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2022\/05\/permission-to-user-only.webp\" alt=\"permission to user only\" width=\"805\" height=\"202\" \/><\/a><\/p>\n<p>You can also use the flags \u201c-, +, =\u201d and write:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">chmod a+rwx, u-x, g-rwx, o-rwx &lt;filename&gt;<\/pre>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2022\/05\/flags-for-user-permission.webp\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-109738\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2022\/05\/flags-for-user-permission.webp\" alt=\"flags for user permission\" width=\"780\" height=\"172\" \/><\/a><\/p>\n<p>Let us look into the last command in slightly more detail:<\/p>\n<p>First, we assign the permissions to read, write and execute to all the users (a), then from the user we removed the command of executing by using the \u2018-\u2019 flag. We also removed the permissions of reading, writing, and executing from the user group and other users.<\/p>\n<p><strong>c. \u201crw-rw-r&#8211;\u201d<\/strong><\/p>\n<p>To give the permissions of reading and writing to the user and user group and only reading to another user, you can use the octal notation and write:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">chmod 664 &lt;filename&gt;<\/pre>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2022\/05\/octal664.webp\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-109739\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2022\/05\/octal664.webp\" alt=\"octal664\" width=\"666\" height=\"196\" \/><\/a><\/p>\n<p>Or you can use the flags \u201cu, g, o, a\u201d and write:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">chmod u = rw, g= rw, o=r &lt;filename&gt;<\/pre>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2022\/05\/flag-for-only-reading-to-others.webp\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-109740\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2022\/05\/flag-for-only-reading-to-others.webp\" alt=\"flag for only reading to others\" width=\"700\" height=\"176\" \/><\/a><\/p>\n<p>You can also use the flags \u201c-, +, =\u201d and write:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">chmod a+rwx, u-x, g-x, o-wx &lt;filename&gt;<\/pre>\n<h4><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2022\/05\/flag-signs.webp\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-109741\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2022\/05\/flag-signs.webp\" alt=\"flag signs\" width=\"911\" height=\"208\" \/><\/a><\/h4>\n<h4>Options used with chmod<\/h4>\n<p>Now that we have seen how to use chmod in linux to give permission, let us look into the different options that are used with Linux chmod command:<\/p>\n<p><strong>a. -v<\/strong><\/p>\n<p>This option provides verbose by providing a diagnostic message for every single file processed. This option can also be written as: &#8211;verbose.<\/p>\n<p><strong>b. -c<\/strong><\/p>\n<p>This option is similar to verbose, except it gives verbose output only when a change is made to a file. This option can also be written as: &#8211;change.<\/p>\n<p><strong>c. -f<\/strong><\/p>\n<p>This option suppresses most of the error messages. This option can also be written as: \u2018&#8211;silent\u2019 or \u2018&#8211;quiet.<\/p>\n<p><strong>d. &#8211;help<\/strong><\/p>\n<p>This option displays a message and exits.<\/p>\n<p><strong>e. &#8211;version<\/strong><\/p>\n<p>This option outputs the version information and exits.<\/p>\n<p><strong>f. -R<\/strong><\/p>\n<p>This option changes file directories recursively. This option can also be written as: &#8211;recursive.<\/p>\n<p><strong>g. &#8211;reference=RFILE<\/strong><\/p>\n<p>This option sets permissions to match those of the RFILE, ignoring any specific mode.<\/p>\n<p><strong>h. &#8211;preserve-root<\/strong><\/p>\n<p>This option does not operate recursively on \u2018\/\u2019 (the root directory).<\/p>\n<p><strong>i. &#8211;no-preserve-root<\/strong><\/p>\n<p>This option does not treat \u2018\/\u2019(the root directory) in any special way.<\/p>\n<h3>Examples of chmod in Linux<\/h3>\n<p>Now that we have covered the different permissions, flags options, and octal notation, let us see a few examples using chmod in Linux.<\/p>\n<h4>1. Giving user group permission to read<\/h4>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">chmod g=r &lt;filename&gt;<\/pre>\n<p>This command gives the members of the group permission to only read the file and not to write or execute it.<\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2022\/05\/giving-user-group-permission-to-read.webp\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-109728\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2022\/05\/giving-user-group-permission-to-read.webp\" alt=\"giving user group permission to read\" width=\"685\" height=\"199\" \/><\/a><\/p>\n<h4>2. Removing executing permission for all users<\/h4>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">chmod a-r &lt;filename&gt;\r\nchmod 666 &lt;filename&gt;<\/pre>\n<p>This command removes the executing permission to all the users, including the owner.<\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2022\/05\/removing-executing-permission-for-all-users.webp\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-109729\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2022\/05\/removing-executing-permission-for-all-users.webp\" alt=\"removing executing permission for all users\" width=\"668\" height=\"194\" \/><\/a><\/p>\n<h4>3. Recursively removing the write permission for others<\/h4>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">chmod -R o-w &lt;filename&gt;<\/pre>\n<p>This command recursively (-R) removes the writing permission to the other users.<\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2022\/05\/recursively-removing-the-write-permission-for-others.webp\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-109730\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2022\/05\/recursively-removing-the-write-permission-for-others.webp\" alt=\"recursively removing the write permission for others\" width=\"698\" height=\"193\" \/><\/a><\/p>\n<h4>4. Removing \u2018rwx\u2019 for all users except owner<\/h4>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">chmod og-rwx &lt;filename&gt;\r\nchmod 700 &lt;filename&gt;<\/pre>\n<p>This command removes permissions to read, write, and execute from the user group and other users (all except the user). This command can also be written as:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">chmod og= filename<\/pre>\n<h4><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2022\/05\/removing-permission-for-all-users-except-owner.webp\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-109731\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2022\/05\/removing-permission-for-all-users-except-owner.webp\" alt=\"removing permission for all users except owner\" width=\"704\" height=\"208\" \/><\/a><\/h4>\n<h4>5. Giving \u2018rwx\u2019 to the user, \u2018r\u2019 to the group, and nothing to others<\/h4>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">chmod u=rwx, g=r, o= &lt;filename&gt;\r\nchmod 740 &lt;filename&gt;<\/pre>\n<p>This command gives the permission to read, write, and execute from the user. Gives permission to read to the user group and other users get no permissions.<\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2022\/05\/giving-no-permission-to-others.webp\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-109732\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2022\/05\/giving-no-permission-to-others.webp\" alt=\"giving no permission to others\" width=\"765\" height=\"192\" \/><\/a><\/p>\n<h3>What are setuid and setgid bits<\/h3>\n<p>The chmod tool clears the set-group-ID bit of a regular file if the file\u2019s group ID does not match either the user\u2019s group ID or one of the user\u2019s supplementary group ID.<\/p>\n<p>Extra restrictions may cause the set-user-ID (setuid) and set-groupID (setgid) bits of MODE or RFILE to be ignored. This depends on the policy and functionality of the underlying chmod call system.<\/p>\n<p>Linux Chmod protects a directory\u2019s setuid and setgid bits unless you specifically specify it. You can also set or clear these bits with the options we discussed earlier like \u201cu+s\u201d and \u201cg-s\u201d.<\/p>\n<h3>What is a sticky bit?<\/h3>\n<p>A sticky bit or restricted deletion flag is a single bit whose interpretation depends on the file type. In directories, it prevents deprived users from removing or renaming any file in that directory unless they own that file.<\/p>\n<p>A restricted deletion flag for a directory is commonly found on world-writable directories like \/tmp. For normal files on older systems, the bit saves the program\u2019s text image on the swap device so it loads quicker when run. This is what sticky nits are.<\/p>\n<h3>Summary<\/h3>\n<p>As you have seen, chmod is an extremely powerful tool, which allow you to change or assign permissions to different people in linux. Since you are the master, you can control who can read, write and execute a particular file or directory.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In this article, you will learn what Linuchmod is and its use, and understand the different file permissions. We will also see the syntax of the chmod command and the options used along with&#46;&#46;&#46;<\/p>\n","protected":false},"author":1,"featured_media":109726,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[35],"tags":[26943,26944],"class_list":["post-109693","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-linux","tag-chmod-in-linux","tag-linux-chmod-command"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.8 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Chmod in Linux - DataFlair<\/title>\n<meta name=\"description\" content=\"Learn What is chmod command in linux, its use, need, file permissions, octal notation of permission, how to give and remove permissions etc.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/data-flair.training\/blogs\/chmod-in-linux\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Chmod in Linux - DataFlair\" \/>\n<meta property=\"og:description\" content=\"Learn What is chmod command in linux, its use, need, file permissions, octal notation of permission, how to give and remove permissions etc.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/data-flair.training\/blogs\/chmod-in-linux\/\" \/>\n<meta property=\"og:site_name\" content=\"DataFlair\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/DataFlairWS\/\" \/>\n<meta property=\"article:published_time\" content=\"2022-06-14T03:30:51+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2022-06-14T04:27:21+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2022\/05\/linux-chmod.webp\" \/>\n\t<meta property=\"og:image:width\" content=\"1200\" \/>\n\t<meta property=\"og:image:height\" content=\"628\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/webp\" \/>\n<meta name=\"author\" content=\"DataFlair Team\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@DataFlairWS\" \/>\n<meta name=\"twitter:site\" content=\"@DataFlairWS\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"DataFlair Team\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"13 minutes\" \/>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Chmod in Linux - DataFlair","description":"Learn What is chmod command in linux, its use, need, file permissions, octal notation of permission, how to give and remove permissions etc.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/data-flair.training\/blogs\/chmod-in-linux\/","og_locale":"en_US","og_type":"article","og_title":"Chmod in Linux - DataFlair","og_description":"Learn What is chmod command in linux, its use, need, file permissions, octal notation of permission, how to give and remove permissions etc.","og_url":"https:\/\/data-flair.training\/blogs\/chmod-in-linux\/","og_site_name":"DataFlair","article_publisher":"https:\/\/www.facebook.com\/DataFlairWS\/","article_published_time":"2022-06-14T03:30:51+00:00","article_modified_time":"2022-06-14T04:27:21+00:00","og_image":[{"width":1200,"height":628,"url":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2022\/05\/linux-chmod.webp","type":"image\/webp"}],"author":"DataFlair Team","twitter_card":"summary_large_image","twitter_creator":"@DataFlairWS","twitter_site":"@DataFlairWS","twitter_misc":{"Written by":"DataFlair Team","Est. reading time":"13 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/data-flair.training\/blogs\/chmod-in-linux\/#article","isPartOf":{"@id":"https:\/\/data-flair.training\/blogs\/chmod-in-linux\/"},"author":{"name":"DataFlair Team","@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/person\/b49855299264df5e27e3ec6c2cd9fde9"},"headline":"Chmod in Linux","datePublished":"2022-06-14T03:30:51+00:00","dateModified":"2022-06-14T04:27:21+00:00","mainEntityOfPage":{"@id":"https:\/\/data-flair.training\/blogs\/chmod-in-linux\/"},"wordCount":1989,"commentCount":0,"publisher":{"@id":"https:\/\/data-flair.training\/blogs\/#organization"},"image":{"@id":"https:\/\/data-flair.training\/blogs\/chmod-in-linux\/#primaryimage"},"thumbnailUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2022\/05\/linux-chmod.webp","keywords":["Chmod in Linux","linux Chmod command"],"articleSection":["Linux Tutorials"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/data-flair.training\/blogs\/chmod-in-linux\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/data-flair.training\/blogs\/chmod-in-linux\/","url":"https:\/\/data-flair.training\/blogs\/chmod-in-linux\/","name":"Chmod in Linux - DataFlair","isPartOf":{"@id":"https:\/\/data-flair.training\/blogs\/#website"},"primaryImageOfPage":{"@id":"https:\/\/data-flair.training\/blogs\/chmod-in-linux\/#primaryimage"},"image":{"@id":"https:\/\/data-flair.training\/blogs\/chmod-in-linux\/#primaryimage"},"thumbnailUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2022\/05\/linux-chmod.webp","datePublished":"2022-06-14T03:30:51+00:00","dateModified":"2022-06-14T04:27:21+00:00","description":"Learn What is chmod command in linux, its use, need, file permissions, octal notation of permission, how to give and remove permissions etc.","breadcrumb":{"@id":"https:\/\/data-flair.training\/blogs\/chmod-in-linux\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/data-flair.training\/blogs\/chmod-in-linux\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/data-flair.training\/blogs\/chmod-in-linux\/#primaryimage","url":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2022\/05\/linux-chmod.webp","contentUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2022\/05\/linux-chmod.webp","width":1200,"height":628,"caption":"linux chmod"},{"@type":"BreadcrumbList","@id":"https:\/\/data-flair.training\/blogs\/chmod-in-linux\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Blog Home","item":"https:\/\/data-flair.training\/blogs\/"},{"@type":"ListItem","position":2,"name":"Linux Tutorials","item":"https:\/\/data-flair.training\/blogs\/category\/linux\/"},{"@type":"ListItem","position":3,"name":"Chmod in Linux"}]},{"@type":"WebSite","@id":"https:\/\/data-flair.training\/blogs\/#website","url":"https:\/\/data-flair.training\/blogs\/","name":"DataFlair","description":"Learn Today. Lead Tomorrow.","publisher":{"@id":"https:\/\/data-flair.training\/blogs\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/data-flair.training\/blogs\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/data-flair.training\/blogs\/#organization","name":"DataFlair","url":"https:\/\/data-flair.training\/blogs\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/logo\/image\/","url":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2016\/07\/Data-Flair.png","contentUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2016\/07\/Data-Flair.png","width":106,"height":48,"caption":"DataFlair"},"image":{"@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/DataFlairWS\/","https:\/\/x.com\/DataFlairWS","https:\/\/www.linkedin.com\/company\/dataflair-web-services-pvt-ltd\/","https:\/\/www.youtube.com\/user\/DataFlairWS"]},{"@type":"Person","@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/person\/b49855299264df5e27e3ec6c2cd9fde9","name":"DataFlair Team","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/ef46b745ddad2fad690af626c6ef29b91809ad0a9f5ef398d07817d8cad042f5?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/ef46b745ddad2fad690af626c6ef29b91809ad0a9f5ef398d07817d8cad042f5?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/ef46b745ddad2fad690af626c6ef29b91809ad0a9f5ef398d07817d8cad042f5?s=96&d=mm&r=g","caption":"DataFlair Team"},"description":"DataFlair Team is a group of passionate educators and industry experts dedicated to providing high-quality online learning resources on programming, Java, Python, C++, DSA, AI, ML, data Science, Android, Flutter, MERN, Web Development, and technology. With years of experience in the field, the team aims to simplify complex topics and help learners advance their careers. At DataFlair, we believe in empowering students and professionals with the knowledge and skills needed to thrive in today\u2019s fast-paced tech industry. Follow us for Free courses, expert insights, tutorials, and practical tips to boost your learning journey.","url":"https:\/\/data-flair.training\/blogs\/author\/datafbdad\/"}]}},"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts\/109693","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/comments?post=109693"}],"version-history":[{"count":3,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts\/109693\/revisions"}],"predecessor-version":[{"id":109743,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts\/109693\/revisions\/109743"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/media\/109726"}],"wp:attachment":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/media?parent=109693"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/categories?post=109693"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/tags?post=109693"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}