{"id":2164,"date":"2025-12-20T07:00:38","date_gmt":"2025-12-20T07:00:38","guid":{"rendered":"https:\/\/blog.ssdnodes.com\/blog\/?p=2164"},"modified":"2026-01-22T13:10:22","modified_gmt":"2026-01-22T13:10:22","slug":"linux-permissions-chmod-755-644-drwxrxrx-explained","status":"publish","type":"post","link":"https:\/\/www.ssdnodes.com\/blog\/linux-permissions-chmod-755-644-drwxrxrx-explained\/","title":{"rendered":"Linux File Permissions Guide: chmod 755, 644, drwxr-xr-x Explained"},"content":{"rendered":"<div id=\"preview1\" class=\"g-b g-b--t1of2 split split-preview\">\n<div id=\"preview\" class=\"preview-html\">\n<p>Understanding Linux permissions might seem like a near-impossible task\u2014what does <code>755<\/code> , <code>644<\/code>, or <code>u=rwx,g=rw,o=r<\/code> mean, and what in the world is <code>chmod drwxr-xr-x<\/code>, anyway?\u2014but it\u2019s actually easier than you think. Let\u2019s take a look.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-15011\" style=\"border-radius: 25px;\" src=\"https:\/\/www.ssdnodes.com\/wp-content\/uploads\/2024\/12\/linux-file-permissions_.webp\" alt=\"linux file permissions\" width=\"600\" height=\"400\" \/><\/p>\n<p>Linux is a multi-user operating system that can be accessed by many users simultaneously. This might make you to think that a user can manipulate files and directories of another user, but all Linux operating systems protect filesystems under two levels of authorization\u2014<em>ownership<\/em> and <em>permission<\/em>\u2014to prevent unauthorized access to the filesystem in an effective and easy manner.<\/p>\n<\/div>\n<p><strong>Note:<\/strong> The best way to master these permissions is to get your own\u00a0<strong><a href=\"http:\/\/ssdnodes.com\" target=\"_blank\" rel=\"noopener\">Linux VPS server<\/a><\/strong> and learn by doing. The best part? We provide the best <a href=\"https:\/\/www.ssdnodes.com\/blog\/cheap-linux-vps-comparison-report\/\">low-cost reliable VPS plans<\/a> in the market!<\/p>\n<blockquote><p>Want an easy way to calculate Linux permissions? Check out our handy <a href=\"https:\/\/www.ssdnodes.com\/chmod-calculator\/\">Chmod Calculator<\/a>.<\/p><\/blockquote>\n<div class=\"cl-preview-section\">\n<h2 id=\"how-to-view-file-permissions-in-linux\">How to View File Permissions in Linux<\/h2>\n<\/div>\n<div class=\"cl-preview-section\">\n<p>To view file permissions in Linux, use the\u00a0<code>ls -l<\/code>\u00a0command. This displays the permission string, owner, group, and other file details:<\/p>\n<\/div>\n<div class=\"cl-preview-section\">\n<pre class=\" language-bash\"><code class=\"prism language-bash\">$ <span class=\"token function\">ls<\/span> -l\r\ndrwxr-xr-x  3 <span class=\"token function\">dd<\/span> <span class=\"token function\">users<\/span>   4096 Jun  10 08:01 Pictures\r\n-rw-r--r--  1 <span class=\"token function\">dd<\/span> <span class=\"token function\">users<\/span>   2048 Jun  15 14:30 readme.txt\r\n<\/code><\/pre>\n<\/div>\n<div class=\"cl-preview-section\">\n<p>The ten-character string at the beginning shows the permissions. You can also view file permissions for a specific file:<\/p>\n<\/div>\n<div class=\"cl-preview-section\">\n<pre class=\" language-bash\"><code class=\"prism language-bash\">$ <span class=\"token function\">ls<\/span> -l filename\r\n<\/code><\/pre>\n<\/div>\n<div class=\"cl-preview-section\">\n<p>For a more detailed view showing permissions in both symbolic and numeric formats, use the\u00a0<code>stat<\/code>\u00a0command:<\/p>\n<\/div>\n<div class=\"cl-preview-section\">\n<pre class=\" language-bash\"><code class=\"prism language-bash\">$ <span class=\"token function\">stat<\/span> filename<\/code><\/pre>\n<\/div>\n<div id=\"preview\" class=\"preview-html\">\n<h2>How do I find the permissions of a file?<\/h2>\n<p>Let\u2019s try to find the permissions of files and directories. To find the permissions that is already assigned to files or directories, use <code>ls<\/code> command with <code>-l<\/code> switch.<\/p>\n<pre><code>$ ls -l\r\ndrwxr-xr-x  3 dd users   4096 Jun  10 08:01 Pictures\r\n...\r\n...\r\n<\/code><\/pre>\n<p>The first ten characters in the format <code>drwxrwxrwx<\/code>, represents the permissions for all the three classes of users. Let\u2019s try to understand what each of these letters means. The first character, <code>d<\/code>, signifies that the file is a directory. This position can be blank(-) or any of the following characters:<\/p>\n<pre><code>c: Character device\r\nb: Block device\r\ns: socket\r\np: pipe\r\nl: symbolic link etc.\r\n<\/code><\/pre>\n<p>Then the next three characters (d<strong>rwx<\/strong>r-xr-x) represent the permissions that have been assigned to the owners of the file. The owner <code>dd<\/code> can read, write, and execute to the folder <code>Pictures<\/code>.<\/p>\n<p>Moving on to the next three characters (drwx<strong>r-x<\/strong>r-x), which is <code>r-x<\/code>, represents the group permissions. The users from <code>users<\/code> group can access the file according to the group permissions, which specify they can read and execute in the directory but cannot write into it. The hyphen signifies that the permission is not granted.<\/p>\n<p>The last three characters (drwxr-x<strong>r-x<\/strong>) represents the permissions for <code>other<\/code> groups who are neither the owner nor a member of the group <code>users<\/code> and the permissions are set to read and execute only.<\/p>\n<p>The 11th character is a number that represents the number of hard links for the file and is not related to permission for a file. The two columns next to this number (drwxr-xr-x 3 <strong>dd users<\/strong>) represents the owner and group of the file.<\/p>\n<p>To find the permissions for a particular file or directory, specify the name of the file in the <code>ls<\/code> command like below.<\/p>\n<pre><code>$ ls -l filename<\/code><\/pre>\n<h2>Owners of files, directories, and processes<\/h2>\n<p>Before we try to explore who are the owners of files and directories, let\u2019s get an overview of user types in Linux. In Linux, there are two types of users, <em>system<\/em> users and <em>regular<\/em> users. System users are created by the operating system itself and are used to manage background processes.<\/p>\n<p>We generally create regular users to create and run processes interactively through a GUI or terminal. Besides these two types of users, there is a <em>superuser<\/em> by the name <code>root<\/code>, which has access to entire system to manage and override any settings in the system.<\/p>\n<p>In Linux, the owners of the files, directories and processes will be assigned to these three types of users: regular, system, or root. Before we try to explore what permissions can be assigned to these three types of users, let\u2019s try to understand the types of permission that are available in Linux.<\/p>\n<h2>What Linux permissions types are there?<\/h2>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-8734\" src=\"https:\/\/www.ssdnodes.com\/wp-content\/uploads\/2018\/07\/permissions-1-1024x432.png\" alt=\"Linux Permissions: 755, drwxr-xr-x, 644, chmod\" width=\"600\" height=\"253\" srcset=\"https:\/\/www.ssdnodes.com\/wp-content\/uploads\/2018\/07\/permissions-1-1024x432.png 1024w, https:\/\/www.ssdnodes.com\/wp-content\/uploads\/2018\/07\/permissions-1-300x127.png 300w, https:\/\/www.ssdnodes.com\/wp-content\/uploads\/2018\/07\/permissions-1-768x324.png 768w, https:\/\/www.ssdnodes.com\/wp-content\/uploads\/2018\/07\/permissions-1.png 1200w\" sizes=\"auto, (max-width: 600px) 100vw, 600px\" \/><\/p>\n<p>There are two levels of permissions assigned to the files, directories, and processes in Linux. The first one is <em>permission groups<\/em>, which is otherwise referred to as the <em>ownership<\/em>. The second one is <em>permission types<\/em>, which can be <code>read<\/code>, <code>write<\/code>, or <code>execute<\/code>.<\/p>\n<h3>Permission groups<\/h3>\n<p>For every file and directory in Linux, there are the sets of users for whom we specify permissions. They are:<\/p>\n<ul>\n<li>Owners<\/li>\n<li>Groups<\/li>\n<li>Others<\/li>\n<\/ul>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-15010\" style=\"border-radius: 25px;\" src=\"https:\/\/www.ssdnodes.com\/wp-content\/uploads\/2024\/12\/Linux-Directory-Permissions-Tree_.webp\" alt=\"Linux Directory Permissions Tree\" width=\"600\" height=\"400\" \/><\/p>\n<p><strong>Owners<\/strong>: The user who creates a file, folder, or process is the <code>owners<\/code>.<\/p>\n<p><strong>Groups<\/strong>: <code>Groups<\/code> refers to anyone who is in the same group as the owner.<\/p>\n<p><strong>Others<\/strong>: Any user who is neither the owner of the file\/directory and doesn\u2019t belong to the same group is assigned to <code>others<\/code> group.<\/p>\n<h3>Permission types<\/h3>\n<p>What operations can each of the above three user groups can do is defined by <code>permission types<\/code>. There are three basic <code>permission types<\/code> that can be assigned to three groups of users and they are <em>read<\/em> <code>(r)<\/code> , <em>write<\/em> <code>(w)<\/code>, and <em>execute<\/em> <code>(x)<\/code>.<\/p>\n<h3>What do read, write and execute mean for files and directories ?<\/h3>\n<p><strong>For files:<\/strong><\/p>\n<ul>\n<li>Read is the ability to view the contents of a file.<\/li>\n<li>Write is the ability to edit or delete a file.<\/li>\n<li>Execute is the ability to run a file as an executable program.<\/li>\n<\/ul>\n<p><strong>For directories:<\/strong><\/p>\n<ul>\n<li>Read is the ability to read the contents of a directory.<\/li>\n<li>Write is the ability to write into the directory, like creating files and sub-directories inside a directory.<\/li>\n<li>Execute is the ability to <code>cd<\/code> into the directory and to view the metadata of the files inside the directory using <code>ls<\/code> command.<\/li>\n<\/ul>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-15013\" style=\"border-radius: 25px;\" src=\"https:\/\/www.ssdnodes.com\/wp-content\/uploads\/2024\/12\/rwx-Permission-States-_-.webp\" alt=\"rwx Permission States \" width=\"600\" height=\"400\" \/><\/p>\n<h2>Permissions in numeric notation<\/h2>\n<p>Two notations are used to represents the permissions for files and folders. The one that we already came about (r,w,x) is known as <em>symbolic notation<\/em>. The other one is <em>numeric notation<\/em>. In this notation, a number (0,1,2,4) represents a permission and are as follows:<\/p>\n<ul>\n<li>0: No permission<\/li>\n<li>1: Execute (x)<\/li>\n<li>2: Write (w)<\/li>\n<li>4: Read (r)<\/li>\n<\/ul>\n<p>Now, how to calculate permissions for users and groups in numeric notation? Just add the permission\u2019s value to get the value of user, group, and other permissions respectively.<\/p>\n<p>For example:<\/p>\n<p>read(4), write(2) and execute(1) permission <code>rwx<\/code> translated to <code>7<\/code> (4+2+1)<br \/>\nread(4) and write(2) permission <code>rw-<\/code> translated to <code>6<\/code> (4+2)<br \/>\nwrite(2) and execute(1) permission <code>-wx<\/code> translated to <code>3<\/code> (2+1) etc.<\/p>\n<p>Therefore the permission <code>rwxrwxrwx<\/code> is same as <code>777<\/code>, <code>rwxr-xr-x<\/code> is same as <code>755<\/code>, and so on.<\/p>\n<h2>Understanding 755 Permissions (chmod 755)<\/h2>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-15009\" style=\"border-radius: 25px;\" src=\"https:\/\/www.ssdnodes.com\/wp-content\/uploads\/2024\/12\/chmod-755-visual-representation_.webp\" alt=\"chmod 755 visual representation\" width=\"600\" height=\"400\" \/><\/p>\n<div class=\"cl-preview-section\">\n<p>The chmod 755 command sets permissions to rwxr-xr-x, which is one of the most common permission patterns in Linux. Understanding chmod 755 meaning is essential: the owner gets full control (read, write, execute), while group members and others can read and execute but cannot modify the file.<\/p>\n<\/div>\n<div class=\"cl-preview-section\">\n<p>When you run\u00a0<code>chmod 755<\/code>\u00a0on a file or directory, you\u2019re explicitly setting these three permission levels at once. This makes 755 permissions ideal for directories and executable scripts that should be accessible to all users but modifiable only by the owner.<\/p>\n<\/div>\n<h2>Understanding 644 Permissions (chmod 644)<\/h2>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-15007\" style=\"border-radius: 25px;\" src=\"https:\/\/www.ssdnodes.com\/wp-content\/uploads\/2024\/12\/644-permission-in-linux-visual-representation_.webp\" alt=\"644 permission in linux\" width=\"600\" height=\"400\" \/><\/p>\n<p>The chmod 644 command is the standard permission for regular files. When you set 644 permissions, the owner can read and write the file, while group members and others can only read it. This is the default permission for most text files, configuration files, and web content where you want everyone to view but only the owner to modify.<\/p>\n<div class=\"cl-preview-section\">\n<p>To apply 644 permissions to a file:<\/p>\n<\/div>\n<div class=\"cl-preview-section\">\n<pre class=\" language-bash\"><code class=\"prism language-bash\">$ <span class=\"token function\">chmod<\/span> 644 config.conf\r\n<\/code><\/pre>\n<\/div>\n<div class=\"cl-preview-section\">\n<p>This is commonly used for web server files like HTML pages, PHP scripts (that aren\u2019t executable), and configuration files like\u00a0<code>.bashrc<\/code>\u00a0or\u00a0<code>nginx.conf<\/code>.<\/p>\n<\/div>\n<h2>Understanding 711 Permissions (chmod 711)<\/h2>\n<div class=\"cl-preview-section\">\n<p>The chmod 711 command sets permissions where the owner has full control (rwx) while group members and others can only execute (traverse) the file or directory. When you apply 711 permissions, others cannot read or write, making this useful for directories where you want to hide the file listing but still allow access to specific files inside.<\/p>\n<\/div>\n<div class=\"cl-preview-section\">\n<p>This permission pattern is particularly valuable for user home directories in multi-user environments. For example:<\/p>\n<\/div>\n<div class=\"cl-preview-section\">\n<pre class=\" language-bash\"><code class=\"prism language-bash\">$ <span class=\"token function\">chmod<\/span> 711 \/home\/username\r\n<\/code><\/pre>\n<\/div>\n<div class=\"cl-preview-section\">\n<p>With 711 permissions on a home directory, other users can access files like\u00a0<code>\/home\/username\/public_html\/index.html<\/code>\u00a0if they know the path, but they can\u2019t run\u00a0<code>ls<\/code>\u00a0to see what files exist in your home directory.<\/p>\n<\/div>\n<h2>Understanding 700 Permissions (chmod 700)<\/h2>\n<div class=\"cl-preview-section\">\n<p>The chmod 700 command provides maximum privacy by granting full permissions (rwx) to the owner while completely blocking access for group members and others. When you set 700 permissions, only you can read, write, or execute the file or directory\u2014everyone else is locked out entirely.<\/p>\n<\/div>\n<div class=\"cl-preview-section\">\n<p>This is the required permission for sensitive directories like your SSH configuration:<\/p>\n<\/div>\n<div class=\"cl-preview-section\">\n<pre class=\" language-bash\"><code class=\"prism language-bash\">$ <span class=\"token function\">chmod<\/span> 700 ~\/.ssh\r\n<\/code><\/pre>\n<\/div>\n<div class=\"cl-preview-section\">\n<p>Using chmod 700 is critical for security-sensitive locations. SSH will actually refuse to work if your\u00a0<code>.ssh<\/code>\u00a0directory has more permissive settings, as it could allow unauthorized users to access your private keys.<\/p>\n<\/div>\n<h2>Understanding 600 Permissions (chmod 600)<\/h2>\n<div class=\"cl-preview-section\">\n<p>The chmod 600 command restricts all access to the owner only, allowing read and write but no execute permission. When you apply 600 permissions to a file, group members and others cannot view, modify, or execute it. This is the standard security setting for private files containing sensitive data.<\/p>\n<\/div>\n<div class=\"cl-preview-section\">\n<p>The most critical use of chmod 600 is for SSH private keys:<\/p>\n<\/div>\n<div class=\"cl-preview-section\">\n<pre class=\" language-bash\"><code class=\"prism language-bash\">$ <span class=\"token function\">chmod<\/span> 600 ~\/.ssh\/id_rsa\r\n$ <span class=\"token function\">chmod<\/span> 600 ~\/.ssh\/id_ed25519\r\n<\/code><\/pre>\n<\/div>\n<div class=\"cl-preview-section\">\n<p>SSH requires 600 permissions on private keys\u2014if the permissions are more permissive, SSH will display an error like \u201cUNPROTECTED PRIVATE KEY FILE\u201d and refuse to use the key. This security measure prevents other users on the system from reading your authentication credentials.<\/p>\n<\/div>\n<div class=\"cl-preview-section\">\n<p>Other common uses for 600 permissions include password files, API tokens, database credential files, and any configuration containing secrets.<\/p>\n<\/div>\n<\/div>\n<\/div>\n<div class=\"cl-preview-section\">\n<h2 id=\"decoding-drwxr-xr-x-permissions\">Decoding drwxr-xr-x Permissions<\/h2>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-15008\" style=\"border-radius: 25px;\" src=\"https:\/\/www.ssdnodes.com\/wp-content\/uploads\/2024\/12\/drwxr-xr-x-permission_.webp\" alt=\"drwxr-xr-x linux permission visual\" width=\"600\" height=\"400\" \/><\/p>\n<\/div>\n<div class=\"cl-preview-section\">\n<p>The permission string\u00a0<code>drwxr-xr-x<\/code>\u00a0is one of the most common patterns you\u2019ll see in Linux. Let\u2019s break down what drwxr-xr-x means:<\/p>\n<\/div>\n<div class=\"cl-preview-section\">\n<ul>\n<li><strong>d<\/strong>\u00a0= This is a directory (not a file)<\/li>\n<li><strong>rwx<\/strong>\u00a0= Owner has read, write, and execute permissions<\/li>\n<li><strong>r-x<\/strong>\u00a0= Group has read and execute permissions (no write)<\/li>\n<li><strong>r-x<\/strong>\u00a0= Others have read and execute permissions (no write)<\/li>\n<\/ul>\n<\/div>\n<div class=\"cl-preview-section\">\n<p>When you see drwxr-xr-x in your terminal output, it indicates a directory with 755 permissions. This is the standard permission for most directories on a Linux system. To set drwxr-xr-x permissions on a directory:<\/p>\n<\/div>\n<div class=\"cl-preview-section\">\n<pre class=\" language-bash\"><code class=\"prism language-bash\">$ <span class=\"token function\">chmod<\/span> 755 my-directory\r\n$ <span class=\"token function\">ls<\/span> -ld my-directory\r\ndrwxr-xr-x 2 username group 4096 Dec 20 10:00 my-directory\r\n<\/code><\/pre>\n<\/div>\n<div class=\"cl-preview-section\">\n<p>The drwxr-xr-x pattern allows the owner to create, delete, and rename files inside the directory, while other users can browse the directory contents and access files but cannot modify the directory structure itself.<\/p>\n<\/div>\n<div id=\"preview1\" class=\"g-b g-b--t1of2 split split-preview\">\n<div id=\"preview\" class=\"preview-html\">\n<h2>Changing Linux permissions using chmod<\/h2>\n<p>Using the <code>chmod<\/code> command, one can add or remove permissions from a file or a directory. The letters <code>u<\/code> (owner\/user), <code>g<\/code> (group) and <code>o<\/code> (other) are used to add or remove permissions for each of the three user types along with following three signs.<\/p>\n<ul>\n<li>the minus sign (<code>-<\/code>), which means \u201cremove these permissions\u201d<\/li>\n<li>the plus sign (<code>+<\/code>), which means \u201cadd these permissions\u201d<\/li>\n<li>the equals sign (<code>=<\/code>), which means \u201cchange the permissions to exactly these\u201d.<\/li>\n<\/ul>\n<h3>Add permissions using chmod<\/h3>\n<p>To add permissions, use <code>chmod<\/code> command along with plus sign (<code>+<\/code>), which means \u201cadd these permissions\u201d.<\/p>\n<p>So if you want to add execute permission for all three types of users for a script file, use the following <code>chmod<\/code> command.<\/p>\n<pre><code>$ chmod +x hello.sh\r\n         OR\r\n$ chmod a+x hello.sh\r\n\/\/ 'a' means all\r\n<\/code><\/pre>\n<p>To add execute permission for owner of the file only, use the following <code>chmod<\/code> command.<\/p>\n<pre><code>$ chmod u+x hello.sh\r\n<\/code><\/pre>\n<p>Similarly, you can use <code>+r<\/code> to add the read permissions, and <code>+w<\/code> to add the write permissions.<\/p>\n<p>You may also assign permissions to users, groups and others or by combining them selectively. Just specify the classes of users (u, g, or o) and the permission (r, w, or x) that you want to assign. For example, the following <code>chmod<\/code> command will add execute and write permission to the owner of the file.<\/p>\n<pre><code>$ chmod u+xw hello.sh\r\n<\/code><\/pre>\n<p>To add write permission to both the owners and groups use the following command.<\/p>\n<pre><code>$ chmod ug+w hello.sh\r\n<\/code><\/pre>\n<p>You can also add permissions for multiple classes of users at one go. The following example will set read, write and execute permission for owner, and read and write permission for group and others.<\/p>\n<pre><code>$ chmod u=rwx,g=rw,o=rw example.txt\r\n<\/code><\/pre>\n<h3>Remove permissions using chmod<\/h3>\n<div class=\"cl-preview-section\">\n<p>In some situations, you may need to remove permissions rather than add them\u2014whether you\u2019re securing a file, restricting access after sharing, or fixing overly permissive settings. Just change\u00a0<code>+<\/code>\u00a0to\u00a0<code>-<\/code>\u00a0to remove permissions for any of the three classes of users.<\/p>\n<\/div>\n<div class=\"cl-preview-section\">\n<h4 id=\"basic-permission-removal\">Basic Permission Removal<\/h4>\n<\/div>\n<div class=\"cl-preview-section\">\n<pre class=\" language-bash\"><code class=\"prism language-bash\"><span class=\"token comment\"># Remove write permission from group<\/span>\r\n$ <span class=\"token function\">chmod<\/span> g-w readme.txt\r\n\r\n<span class=\"token comment\"># Remove execute permission from both owner and group<\/span>\r\n$ <span class=\"token function\">chmod<\/span> ug-x script.sh\r\n\r\n<span class=\"token comment\"># Remove all permissions from group and others recursively<\/span>\r\n$ <span class=\"token function\">chmod<\/span> -R go-rwx test_directory\r\n<\/code><\/pre>\n<\/div>\n<div class=\"cl-preview-section\">\n<p>The recursive example (<code>-R<\/code>) removes read, write, and execute permissions for groups and other users from\u00a0<code>test_directory<\/code>\u00a0including all files and subdirectories inside it.<\/p>\n<\/div>\n<div class=\"cl-preview-section\">\n<h4 id=\"removing-multiple-permissions-at-once\">Removing Multiple Permissions at Once<\/h4>\n<\/div>\n<div class=\"cl-preview-section\">\n<p>You can remove several permissions in a single command:<\/p>\n<\/div>\n<div class=\"cl-preview-section\">\n<pre class=\" language-bash\"><code class=\"prism language-bash\"><span class=\"token comment\"># Remove write and execute from others<\/span>\r\n$ <span class=\"token function\">chmod<\/span> o-wx script.sh\r\n\r\n<span class=\"token comment\"># Remove all permissions from others<\/span>\r\n$ <span class=\"token function\">chmod<\/span> o-rwx confidential.txt\r\n\r\n<span class=\"token comment\"># Remove read from group, write from others<\/span>\r\n$ <span class=\"token function\">chmod<\/span> g-r,o-w shared-file.txt\r\n<\/code><\/pre>\n<\/div>\n<div class=\"cl-preview-section\">\n<h4 id=\"common-security-scenarios\">Common Security Scenarios<\/h4>\n<\/div>\n<div class=\"cl-preview-section\">\n<p><strong>Making files read-only for non-owners:<\/strong>\u00a0Useful for configuration files that others should reference but not modify:<\/p>\n<\/div>\n<div class=\"cl-preview-section\">\n<pre class=\" language-bash\"><code class=\"prism language-bash\"><span class=\"token comment\"># Remove write permission from group and others<\/span>\r\n$ <span class=\"token function\">chmod<\/span> go-w config.conf\r\n<span class=\"token comment\"># Result: -rw-r--r-- (644 permissions)<\/span>\r\n<\/code><\/pre>\n<\/div>\n<div class=\"cl-preview-section\">\n<p><strong>Securing uploaded files:<\/strong>\u00a0When files are uploaded with overly permissive settings:<\/p>\n<\/div>\n<div class=\"cl-preview-section\">\n<pre class=\" language-bash\"><code class=\"prism language-bash\"><span class=\"token comment\"># Remove write from group\/others, remove execute from all<\/span>\r\n$ <span class=\"token function\">chmod<\/span> go-w,a-x \/var\/www\/uploads\/file.jpg\r\n<span class=\"token comment\"># Result: Files become 644 (rw-r--r--)<\/span>\r\n<\/code><\/pre>\n<\/div>\n<div class=\"cl-preview-section\">\n<p><strong>Locking down private directories:<\/strong>\u00a0After creating a backup or archive:<\/p>\n<\/div>\n<div class=\"cl-preview-section\">\n<pre class=\" language-bash\"><code class=\"prism language-bash\"><span class=\"token comment\"># Remove all access for group and others<\/span>\r\n$ <span class=\"token function\">chmod<\/span> -R go-rwx \/backups\/project-archive\/\r\n<span class=\"token comment\"># Result: Only owner can access<\/span>\r\n<\/code><\/pre>\n<\/div>\n<div class=\"cl-preview-section\">\n<h4 id=\"important-warnings\">Important Warnings<\/h4>\n<\/div>\n<div class=\"cl-preview-section\">\n<p><strong>Directory execute permission:<\/strong>\u00a0Removing execute permission from a directory prevents anyone from entering it, even if they have read\/write:<\/p>\n<\/div>\n<div class=\"cl-preview-section\">\n<pre class=\" language-bash\"><code class=\"prism language-bash\">$ <span class=\"token function\">chmod<\/span> a-x my-directory\/\r\n$ <span class=\"token function\">cd<\/span> my-directory\/\r\nbash: cd: my-directory\/: Permission denied\r\n<\/code><\/pre>\n<\/div>\n<div class=\"cl-preview-section\">\n<p>Always keep execute permission on directories unless you specifically want to block access.<\/p>\n<\/div>\n<div class=\"cl-preview-section\">\n<p><strong>Recursive operations require caution:<\/strong>\u00a0The\u00a0<code>-R<\/code>\u00a0flag affects everything inside a directory. Always verify your command before using recursive removal:<\/p>\n<\/div>\n<div class=\"cl-preview-section\">\n<pre class=\" language-bash\"><code class=\"prism language-bash\"><span class=\"token comment\"># CAREFUL: This locks out everyone from entire web directory<\/span>\r\n$ <span class=\"token function\">chmod<\/span> -R go-rwx \/var\/www\/html\/  <span class=\"token comment\"># Can break your website!<\/span>\r\n\r\n<span class=\"token comment\"># Better: Target specific subdirectories<\/span>\r\n$ <span class=\"token function\">chmod<\/span> -R go-rwx \/var\/www\/html\/private\/\r\n<\/code><\/pre>\n<\/div>\n<div class=\"cl-preview-section\">\n<h4 id=\"combining-add-and-remove\">Combining Add and Remove<\/h4>\n<\/div>\n<div class=\"cl-preview-section\">\n<p>You can add and remove permissions in the same command:<\/p>\n<\/div>\n<div class=\"cl-preview-section\">\n<pre class=\" language-bash\"><code class=\"prism language-bash\"><span class=\"token comment\"># Add execute for owner, remove for group and others<\/span>\r\n$ <span class=\"token function\">chmod<\/span> u+x,go-x script.sh\r\n\r\n<span class=\"token comment\"># Add read for owner, remove write for group<\/span>\r\n$ <span class=\"token function\">chmod<\/span> u+r,g-w document.txt\r\n<\/code><\/pre>\n<\/div>\n<div class=\"cl-preview-section\">\n<h4 id=\"quick-verification\">Quick Verification<\/h4>\n<\/div>\n<div class=\"cl-preview-section\">\n<p>Always check permissions after removing them:<\/p>\n<\/div>\n<div class=\"cl-preview-section\">\n<pre class=\" language-bash\"><code class=\"prism language-bash\">$ <span class=\"token function\">chmod<\/span> go-w important.txt\r\n$ <span class=\"token function\">ls<\/span> -l important.txt\r\n-rw-r--r-- 1 john <span class=\"token function\">users<\/span> 2048 Dec 20 10:00 important.txt\r\n<\/code><\/pre>\n<\/div>\n<div class=\"cl-preview-section\">\n<p><strong>Best practice:<\/strong>\u00a0Remove permissions proactively using the principle of least privilege\u2014it\u2019s easier to add permissions back later than to fix a security breach caused by overly permissive files.<\/p>\n<\/div>\n<h3>Changing Linux permissions using numeric notation<\/h3>\n<p>You can also set permissions using numeric notation instead of symbolic notation. Permissions set in this way use up to four digits. Now you may ask why 4 digits since there are only three classes of users for which you want to set the permissions. The first digits signifies value for <strong>set user id<\/strong> (4) OR <strong>set group id<\/strong> (2) OR <strong>sticky bit<\/strong>(1). The rest of the three digits are used for setting permission for three classes of users.<\/p>\n<p>It is also possible to set permission using 3 digits only leaving the permission for user id, group id and stick bit unset. <em>So the permission <code>0755<\/code> and <code>755<\/code> are the same.<\/em><\/p>\n<pre><code>$ chmod 755 hello.sh\r\n\/\/ Sets all permission to owners and read\/execute permission to group and others\r\n\r\n$ chmod 0755 hello.sh\r\n\/\/ Same as 755\r\n<\/code><\/pre>\n<p>Understanding these numeric commands is essential: chmod 755 gives full access to the owner and read\/execute to others, chmod 644 makes files readable by all but writable only by the owner, chmod 700 creates a private directory, and chmod 600 protects sensitive files. Each chmod command directly translates to a specific rwx pattern.<\/p>\n<h3>Setting the <code>drwxr-xr-x<\/code> permission for a directory using <code>chmod<\/code><\/h3>\n<p>Setting drwxr-xr-x permissions is a common task when managing directories. The drwxr-xr-x format appears frequently because it balances accessibility with security. Everyone can navigate the directory and read files, but only the owner can make changes.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-8732\" src=\"https:\/\/www.ssdnodes.com\/wp-content\/uploads\/2018\/07\/drwxr-xr-x-1-1024x642.png\" alt=\"drwxr-xr-x permission\" width=\"500\" height=\"313\" srcset=\"https:\/\/www.ssdnodes.com\/wp-content\/uploads\/2018\/07\/drwxr-xr-x-1-1024x642.png 1024w, https:\/\/www.ssdnodes.com\/wp-content\/uploads\/2018\/07\/drwxr-xr-x-1-300x188.png 300w, https:\/\/www.ssdnodes.com\/wp-content\/uploads\/2018\/07\/drwxr-xr-x-1-768x481.png 768w, https:\/\/www.ssdnodes.com\/wp-content\/uploads\/2018\/07\/drwxr-xr-x-1.png 1200w\" sizes=\"auto, (max-width: 500px) 100vw, 500px\" \/><\/p>\n<\/div>\n<\/div>\n<p>&nbsp;<\/p>\n<div id=\"preview1\" class=\"g-b g-b--t1of2 split split-preview\">\n<div id=\"preview\" class=\"preview-html\">\n<p>To set the <code>drwxr-xr-x<\/code> permissions to a directory, use the command\u00a0<code>chmod 755 directory_name<\/code>.<\/p>\n<h3>What is <code>chmod 755<\/code> ?<\/h3>\n<p><code>chmod 755<\/code> means granting the owner read, write, and execute permissions, while allowing the group and others to have read and execute permissions on the file.<\/p>\n<h3>Set user id<\/h3>\n<p>If a file with set user ID permission is set, then the file is executed as if by the owner of the file rather than the user who is executing the file. For example, <code>\/bin\/mount<\/code> is commonly owned by <code>root<\/code> and has permissions 4755 where the digit 4 signifies that, even if the file is executed by a normal user, it will run with the owner\u2019s (root\u2019s) privileges since the file is owned by <code>root<\/code>. The following example will show how to set the <code>suid<\/code> bit for a file.<\/p>\n<pre><code>$ chmod u+s hello.sh\r\n        OR\r\n$ chmod 4664 hello.sh\r\n\r\n\/\/ Sets the suid bit of the file hello.sh\r\n\r\n$ ls -l hello.sh\r\n-rwSrw-r-- 1 peter peter 0 Jun 13 10:16 hello.sh\r\n\r\n\/\/ The fourth character in the permission shows the suid bit is set.\r\n\/\/ The capital 'S' signifies that executable bit is not set otherwise executable bit will be 's'\r\n<\/code><\/pre>\n<h3>Set group id<\/h3>\n<p><code>SGID<\/code> can be set to both files and directories and is represented symbolically by <code>g<\/code> and numerically by <code>2<\/code>. When a directory has the <code>sgid<\/code> bit set, any files or directories created inside it will inherit the group ID of the directory. To set the <code>sgid<\/code> bit for a directory, use the following <code>chmod<\/code> command.<\/p>\n<pre><code>$ chmod g+s test_directory\r\n          OR\r\n$ chmod 2755 test_directory\r\n<\/code><\/pre>\n<p>Find if the <code>sgid<\/code> bit is set for the directory using the <code>ls<\/code> command.<\/p>\n<pre><code>$ ls -ld test_directory\/\r\ndrwxrwsr-x 3 peter peter 4096 Jun 12 10:30 test_directory\/\r\n<\/code><\/pre>\n<p>The seventh character in the group permission section (<code>'s'<\/code>) signifies that the <code>sgid<\/code> bit is set for groups.<\/p>\n<h3>Sticky bit<\/h3>\n<p>The next access mode bit is called the <em>sticky bit<\/em> and is represented symbolically by <code>t<\/code> and numerically by <code>1<\/code>. This bit works on directories only. With sticky bit set on a directory, anyone can create files or directories inside it. Files owned by other users cannot be deleted except his own files and directories.<\/p>\n<p>To add a sticky bit to other types of users, use +t option in the <code>chmod<\/code> command.<\/p>\n<pre><code>$ chmod o+t some_directory\r\n<\/code><\/pre>\n<p>To test if the sticky bit is set for the directory use the ls command:<\/p>\n<pre><code>$ ls -ld some_directory\r\ndrwxrwxr-t 2 peter peter 4096 Jun 12 11:47 some_directory\r\n<\/code><\/pre>\n<p>There will be a <code>t<\/code> in the <code>x<\/code> bit section of other users. Also a lowercase <code>t<\/code> implies that the executable bit is also present, otherwise you would see a capital <code>T<\/code><\/p>\n<p>To remove the sticky bit use <code>-<\/code> sign in the <code>chmod<\/code> command:<\/p>\n<pre><code>$ chmod o-t some_directory\r\n<\/code><\/pre>\n<h2>Using <code>chown<\/code> to change ownership<\/h2>\n<p>There may be situations when you need to change the ownership of files and directories. The <code>chown<\/code> command as described below changes the owner and groups of files and directories.<\/p>\n<pre><code>$ chown dd hello.sh\r\n\/\/ changes the owner of the file only.\r\n<\/code><\/pre>\n<p>To change the group ownership, specify a colon or dot followed by group name right after owner name with no spaces between them, the group ownership of the files is changed as well.<\/p>\n<pre><code>$ chown dd:users hello.sh\r\n             OR\r\n$ chown dd.users hello.sh\r\n<\/code><\/pre>\n<p>If no group name is mentioned after colon or dot followed by OWNER, then the user is made the owner of the files and the group of the files is changed to owners login group.<\/p>\n<pre><code>$ chown dd. hello.sh\r\n      OR\r\n$ chown dd: hello.sh\r\n<\/code><\/pre>\n<p>If the owner name is omitted right before colon or dot and a group name is mentioned afterwards then the group ownership is changed. In this case, <code>chown<\/code> performs the same function as <code>chgrp<\/code>.<\/p>\n<pre><code>$ chown .users hello.sh\r\n        OR\r\n$ chown :users hello.sh\r\n<\/code><\/pre>\n<p>To change the owner and group of a directory recursively use -R switch:<\/p>\n<pre><code> $ chown -R dd:admin some_directory\r\n<\/code><\/pre>\n<p>Now that you have a basic idea of permissions in Linux and its usage through <code>chmod<\/code> and <code>chown<\/code>, you can now implement a proper permissions policy to secure your system.<\/p>\n<div id=\"preview1\" class=\"g-b g-b--t1of2 split split-preview\">\n<div id=\"preview\" class=\"preview-html\">\n<h2>How would you represent the Linux permissions <code>rwxr-xr--<\/code>\u00a0in octal notation?<\/h2>\n<\/div>\n<\/div>\n<p>To represent the Linux permissions <code>rwxr-xr--<\/code> in octal notation, you can map each set of permissions to its corresponding octal value. <code>rwx<\/code>\u00a0to 7, <code>r-x<\/code>\u00a0to 5, <code>r--<\/code>\u00a0to 4. So, <code>rwxr-xr--<\/code> in octal notation would be <code>754<\/code>.<\/p>\n<p>&nbsp;<\/p>\n<\/div>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>Understanding Linux permissions might seem like a near-impossible task\u2014what does 755 or u=rwx,g=rw,o=r mean, anyway?\u2014but it\u2019s easier than you think.<\/p>\n","protected":false},"author":19,"featured_media":15081,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"inline_featured_image":false,"footnotes":""},"categories":[18,30],"tags":[237,264],"class_list":["post-2164","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-devops","category-tutorials","tag-linux","tag-permissions"],"acf":[],"_links":{"self":[{"href":"https:\/\/www.ssdnodes.com\/wp-json\/wp\/v2\/posts\/2164","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.ssdnodes.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.ssdnodes.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.ssdnodes.com\/wp-json\/wp\/v2\/users\/19"}],"replies":[{"embeddable":true,"href":"https:\/\/www.ssdnodes.com\/wp-json\/wp\/v2\/comments?post=2164"}],"version-history":[{"count":26,"href":"https:\/\/www.ssdnodes.com\/wp-json\/wp\/v2\/posts\/2164\/revisions"}],"predecessor-version":[{"id":15235,"href":"https:\/\/www.ssdnodes.com\/wp-json\/wp\/v2\/posts\/2164\/revisions\/15235"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.ssdnodes.com\/wp-json\/wp\/v2\/media\/15081"}],"wp:attachment":[{"href":"https:\/\/www.ssdnodes.com\/wp-json\/wp\/v2\/media?parent=2164"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.ssdnodes.com\/wp-json\/wp\/v2\/categories?post=2164"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.ssdnodes.com\/wp-json\/wp\/v2\/tags?post=2164"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}