{"id":5168,"date":"2025-05-16T18:39:04","date_gmt":"2025-05-16T10:39:04","guid":{"rendered":"https:\/\/cicserver.com\/how-to-change-file-or-directory-permissions-via-the-linux-terminalhow-to-change-file-or-directory-permissions-via-the-linux-terminal-gpt\/"},"modified":"2025-05-16T18:39:04","modified_gmt":"2025-05-16T10:39:04","slug":"how-to-change-file-or-directory-permissions-via-the-linux-terminalhow-to-change-file-or-directory-permissions-via-the-linux-terminal-gpt","status":"publish","type":"post","link":"https:\/\/cicserver.com\/de\/how-to-change-file-or-directory-permissions-via-the-linux-terminalhow-to-change-file-or-directory-permissions-via-the-linux-terminal-gpt\/","title":{"rendered":"How To Change File or Directory Permissions via the Linux TerminalHow To Change File or Directory Permissions via the Linux Terminal[\/gpt"},"content":{"rendered":"<p><br \/>\n<\/p>\n<div id=\"article-body\">\n<p>If you\u2019ve ever tried to run a script from the command line in Linux and gotten an error message saying that it\u2019s not executable or attempted to enter a directory only to be blocked by the system, you probably don\u2019t have permissions to do those things. Fortunately, if you have the proper rights or the ability to act as a super user (accessible by using sudo), you can change the permissions on files and directories.<\/p>\n<p>In this how-to we\u2019ll look at the<em> chmod <\/em>command, a powerful command that can change file and directory permissions for the owner, user group members and others. In a section below, we\u2019ll also explain how to tell what group your user is in and exactly what Linux means by \u201cothers.\u201d<\/p>\n<aside data-block-type=\"embed\" data-render-type=\"fte\" data-skip=\"dealsy\" data-widget-type=\"seasonal\" class=\"hawk-base\"\/>\n<p>Whilst you become accustomed to these commands it\u2019s good to work with example empty files and directories and you should take extra care to ensure you are carefully following the instructions.<\/p>\n<aside data-component-name=\"Recirculation:ArticleRiver\" data-nosnippet=\"\">\n<span class=\"bg-secondary-500 text-white text-lg font-bold uppercase py-1 px-2 leading-[1.625rem] sm:leading-[6px] sm:text-sm\"><br \/>\nYou may like<br \/>\n<\/span><\/p>\n<\/aside>\n<p>All the commands in this how-to will work on most Linux machines. We\u2019ve used an Ubuntu LTS install but you could run this how-to on a<a data-analytics-id=\"inline-link\" href=\"https:\/\/www.tomshardware.com\/news\/raspberry-pi\" data-before-rewrite-localise=\"https:\/\/www.tomshardware.com\/news\/raspberry-pi\"> <u>Raspberry Pi<\/u><\/a>. All of the how-to is performed via the Terminal. You can open a terminal window on most Linux machines by pressing <em>ctrl, alt <\/em>and <em>t.<\/em><\/p>\n<h2 id=\"how-to-check-file-permissions-in-linux-3\">How to Check File Permissions in Linux<\/h2>\n<figure class=\"van-image-figure  inline-layout\" data-bordeaux-image-check=\"\">\n<div class=\"image-full-width-wrapper\">\n<div class=\"image-widthsetter\" style=\"max-width:1572px;\">\n<p class=\"vanilla-image-block\" style=\"padding-top:67.81%;\"><picture><source type=\"image\/webp\" srcset=\"https:\/\/cdn.mos.cms.futurecdn.net\/ekbk7JuautTKnAECmHtBYe-320-80.png.webp 320w, https:\/\/cdn.mos.cms.futurecdn.net\/ekbk7JuautTKnAECmHtBYe-480-80.png.webp 480w, https:\/\/cdn.mos.cms.futurecdn.net\/ekbk7JuautTKnAECmHtBYe-650-80.png.webp 650w, https:\/\/cdn.mos.cms.futurecdn.net\/ekbk7JuautTKnAECmHtBYe-970-80.png.webp 970w, https:\/\/cdn.mos.cms.futurecdn.net\/ekbk7JuautTKnAECmHtBYe-1024-80.png.webp 1024w, https:\/\/cdn.mos.cms.futurecdn.net\/ekbk7JuautTKnAECmHtBYe-1200-80.png.webp 1200w\" sizes=\"(min-width: 1000px) 970px, calc(100vw - 40px)\"\/><img decoding=\"async\" alt=\"Change Permissions on the Linux Command Line\" class=\"expandable\" srcset=\"https:\/\/cdn.mos.cms.futurecdn.net\/ekbk7JuautTKnAECmHtBYe-320-80.png 320w, https:\/\/cdn.mos.cms.futurecdn.net\/ekbk7JuautTKnAECmHtBYe-480-80.png 480w, https:\/\/cdn.mos.cms.futurecdn.net\/ekbk7JuautTKnAECmHtBYe-650-80.png 650w, https:\/\/cdn.mos.cms.futurecdn.net\/ekbk7JuautTKnAECmHtBYe-970-80.png 970w, https:\/\/cdn.mos.cms.futurecdn.net\/ekbk7JuautTKnAECmHtBYe-1024-80.png 1024w, https:\/\/cdn.mos.cms.futurecdn.net\/ekbk7JuautTKnAECmHtBYe-1200-80.png 1200w\" sizes=\"(min-width: 1000px) 970px, calc(100vw - 40px)\" loading=\"lazy\" src=\"https:\/\/cdn.mos.cms.futurecdn.net\/ekbk7JuautTKnAECmHtBYe.png\" data-pin-media=\"https:\/\/cdn.mos.cms.futurecdn.net\/ekbk7JuautTKnAECmHtBYe.png\"\/><\/picture><\/p>\n<\/div>\n<\/div><figcaption itemprop=\"caption description\" class=\"inline-layout\"><span class=\"credit\" itemprop=\"copyrightHolder\">(Image credit: Tom&#8217;s Hardware)<\/span><\/figcaption><\/figure>\n<p>To begin, let&#8217;s create a test file in a test directory and take a look at its default permissions. To see the permissions we will use <em>ls <\/em>with the <em>-l<\/em> argument added.<\/p>\n<p>1. <strong>Create a new directory called <\/strong><em><strong>test_directory<\/strong><\/em><\/p>\n<pre class=\"line-numbers language-bash\" language=\"bash\"><code>$ mkdir test_directory<\/code><\/pre>\n<p>2. <strong>Move into the newly created directory<\/strong>.<\/p>\n<div id=\"slice-container-newsletterForm-articleInbodyContent-NTnLGkTvyDQucYwkD9ouDa\" class=\"slice-container newsletter-inbodyContent-slice newsletterForm-articleInbodyContent-NTnLGkTvyDQucYwkD9ouDa slice-container-newsletterForm\">\n<div data-hydrate=\"true\" class=\"newsletter-form__wrapper newsletter-form__wrapper--inbodyContent\">\n<div class=\"newsletter-form__container\">\n<section class=\"newsletter-form__top-bar\"\/>\n<section class=\"newsletter-form__main-section\">\n<p class=\"newsletter-form__strapline\">Get Tom&#8217;s Hardware&#8217;s best news and in-depth reviews, straight to your inbox.<\/p>\n<\/section>\n<\/div>\n<\/div>\n<\/div>\n<pre class=\"line-numbers language-bash\" language=\"bash\"><code>$ cd test_directory<\/code><\/pre>\n<p>3. <strong>Create a new test file called <\/strong><em><strong>test1.txt<\/strong><\/em><strong>.<\/strong><\/p>\n<pre class=\"line-numbers language-bash\" language=\"bash\"><code>$ touch test1.txt<\/code><\/pre>\n<p>4. <strong>List the contents of the directory using <\/strong><em><strong>ls -l<\/strong><\/em><strong>.<\/strong><\/p>\n<pre class=\"line-numbers language-bash\" language=\"bash\"><code>$ ls -l<\/code><\/pre>\n<p>Using <em>ls -l<\/em> gives us a lot more information about the items returned on the list. We should see that<em> test1.txt<\/em> has been created. We are interested in the first 10 characters on the listing which for our test file read <em>&#8211; rw- rw- r&#8211;<\/em>.<\/p>\n<p>The first \u2013 indicates that the object on the list is a file. If we ran<em> ls -l<\/em> and a directory was listed this first character would be a<em> d<\/em>. The next 9 characters are arranged in 3 sets of 3.<\/p>\n<p>The first set of 3 refers to the owner, the second set of 3 refer to user groups and the final set of three refer to others. Each set of 3 characters can contain either \u2013 or r, w, and x. If you can see an r in the set then that set has read permissions granted. If you can see a w that set can write to a file and if you can see an x in the set then that set can execute the file as a script or program.<\/p>\n<p>We can see that our <em>test1.txt <\/em>currently has the owner and group member permissions set to read and write with others only allowed to read. No one has permission to execute the file.<\/p>\n<h2 id=\"how-to-change-linux-file-directory-permissions-quickly-3\">How to Change Linux File \/ Directory Permissions Quickly<\/h2>\n<figure class=\"van-image-figure  inline-layout\" data-bordeaux-image-check=\"\">\n<div class=\"image-full-width-wrapper\">\n<div class=\"image-widthsetter\" style=\"max-width:1572px;\">\n<p class=\"vanilla-image-block\" style=\"padding-top:67.81%;\"><picture><source type=\"image\/webp\" srcset=\"https:\/\/cdn.mos.cms.futurecdn.net\/FPvjdEzu6XTFPABMr9J9pe-320-80.png.webp 320w, https:\/\/cdn.mos.cms.futurecdn.net\/FPvjdEzu6XTFPABMr9J9pe-480-80.png.webp 480w, https:\/\/cdn.mos.cms.futurecdn.net\/FPvjdEzu6XTFPABMr9J9pe-650-80.png.webp 650w, https:\/\/cdn.mos.cms.futurecdn.net\/FPvjdEzu6XTFPABMr9J9pe-970-80.png.webp 970w, https:\/\/cdn.mos.cms.futurecdn.net\/FPvjdEzu6XTFPABMr9J9pe-1024-80.png.webp 1024w, https:\/\/cdn.mos.cms.futurecdn.net\/FPvjdEzu6XTFPABMr9J9pe-1200-80.png.webp 1200w\" sizes=\"(min-width: 1000px) 970px, calc(100vw - 40px)\"\/><img decoding=\"async\" alt=\"Change Permissions on the Linux Command Line\" class=\"expandable\" srcset=\"https:\/\/cdn.mos.cms.futurecdn.net\/FPvjdEzu6XTFPABMr9J9pe-320-80.png 320w, https:\/\/cdn.mos.cms.futurecdn.net\/FPvjdEzu6XTFPABMr9J9pe-480-80.png 480w, https:\/\/cdn.mos.cms.futurecdn.net\/FPvjdEzu6XTFPABMr9J9pe-650-80.png 650w, https:\/\/cdn.mos.cms.futurecdn.net\/FPvjdEzu6XTFPABMr9J9pe-970-80.png 970w, https:\/\/cdn.mos.cms.futurecdn.net\/FPvjdEzu6XTFPABMr9J9pe-1024-80.png 1024w, https:\/\/cdn.mos.cms.futurecdn.net\/FPvjdEzu6XTFPABMr9J9pe-1200-80.png 1200w\" sizes=\"(min-width: 1000px) 970px, calc(100vw - 40px)\" loading=\"lazy\" src=\"https:\/\/cdn.mos.cms.futurecdn.net\/FPvjdEzu6XTFPABMr9J9pe.png\" data-pin-media=\"https:\/\/cdn.mos.cms.futurecdn.net\/FPvjdEzu6XTFPABMr9J9pe.png\"\/><\/picture><\/p>\n<\/div>\n<\/div><figcaption itemprop=\"caption description\" class=\"inline-layout\"><span class=\"credit\" itemprop=\"copyrightHolder\">(Image credit: Tom&#8217;s Hardware)<\/span><\/figcaption><\/figure>\n<p>We can use the <em>chmod <\/em>command to toggle the read, write and execute permissions on and off for the owner, group and others. Let\u2019s begin with changing single permissions for the owner and group.<\/p>\n<p>1. In the <em>test_directory,<\/em> <strong>list the current permissions for <\/strong><em><strong>test1.txt<\/strong><\/em><strong>.<\/strong><\/p>\n<pre class=\"line-numbers language-bash\" language=\"bash\"><code>$ ls -l<\/code><\/pre>\n<p>These should be unchanged from when we created <em>test1.txt <\/em>and should read <em>-rw-rw-r&#8211; .<\/em><\/p>\n<p>2. <strong>Change the permission of the owner to read only<\/strong>.<\/p>\n<pre class=\"line-numbers language-bash\" language=\"bash\"><code>$ chmod u-w test1.txt<\/code><\/pre>\n<p>3. <strong>List the directory contents<\/strong> to view the new permission settings. We should now see that the permissions for <em>test1.txt <\/em>read -r&#8211;rw-r&#8211; indicating that, for the owner, the file is now read only.<\/p>\n<pre class=\"line-numbers language-bash\" language=\"bash\"><code>$ ls -l<\/code><\/pre>\n<p>4. <strong>Change  permission of groups to read only. <\/strong>Similar to changing permissions for the owner we can change permission settings for the groups. To revoke write permissions we can use the argument <em>g-w<\/em>.<\/p>\n<pre class=\"line-numbers language-bash\" language=\"bash\"><code>$ chmod g-w test1.txt<\/code><\/pre>\n<p>5. <strong>List the directory contents <\/strong>to view the new permission settings<strong>.<\/strong><\/p>\n<pre class=\"line-numbers language-bash\" language=\"bash\"><code>$ ls -l<\/code><\/pre>\n<p>We should now see that the permissions for <em>test1.txt <\/em>read -r&#8211;r&#8211;r&#8211; indicating that, for the groups, the file is now read only.<\/p>\n<p>6. <strong>Enable write permissions for the owner. <\/strong>Instead of using <em>u-w <\/em>to remove write permissions we can intuitively use <em>u+w <\/em>to grant write permissions for the owner.<\/p>\n<pre class=\"line-numbers language-bash\" language=\"bash\"><code>$ chmod u+w test1.txt<\/code><\/pre>\n<p>7. <strong>List the directory contents <\/strong>to view the new permission settings. We should now see that the permissions for <em>test1.txt <\/em>read -rw-r&#8211;r&#8211; indicating that, for the owner, write permissions have been granted.<\/p>\n<pre class=\"line-numbers language-bash\" language=\"bash\"><code>$ ls -l<\/code><\/pre>\n<h2 id=\"how-to-apply-multiple-file-directory-permission-changes-in-linux-3\">How to Apply Multiple File \/ Directory Permission Changes in Linux<\/h2>\n<figure class=\"van-image-figure  inline-layout\" data-bordeaux-image-check=\"\">\n<div class=\"image-full-width-wrapper\">\n<div class=\"image-widthsetter\" style=\"max-width:1572px;\">\n<p class=\"vanilla-image-block\" style=\"padding-top:67.81%;\"><picture><source type=\"image\/webp\" srcset=\"https:\/\/cdn.mos.cms.futurecdn.net\/BY3RJGKxbbHd9v4nvuNmge-320-80.png.webp 320w, https:\/\/cdn.mos.cms.futurecdn.net\/BY3RJGKxbbHd9v4nvuNmge-480-80.png.webp 480w, https:\/\/cdn.mos.cms.futurecdn.net\/BY3RJGKxbbHd9v4nvuNmge-650-80.png.webp 650w, https:\/\/cdn.mos.cms.futurecdn.net\/BY3RJGKxbbHd9v4nvuNmge-970-80.png.webp 970w, https:\/\/cdn.mos.cms.futurecdn.net\/BY3RJGKxbbHd9v4nvuNmge-1024-80.png.webp 1024w, https:\/\/cdn.mos.cms.futurecdn.net\/BY3RJGKxbbHd9v4nvuNmge-1200-80.png.webp 1200w\" sizes=\"(min-width: 1000px) 970px, calc(100vw - 40px)\"\/><img decoding=\"async\" alt=\"Change Permissions on the Linux Command Line\" class=\"expandable\" srcset=\"https:\/\/cdn.mos.cms.futurecdn.net\/BY3RJGKxbbHd9v4nvuNmge-320-80.png 320w, https:\/\/cdn.mos.cms.futurecdn.net\/BY3RJGKxbbHd9v4nvuNmge-480-80.png 480w, https:\/\/cdn.mos.cms.futurecdn.net\/BY3RJGKxbbHd9v4nvuNmge-650-80.png 650w, https:\/\/cdn.mos.cms.futurecdn.net\/BY3RJGKxbbHd9v4nvuNmge-970-80.png 970w, https:\/\/cdn.mos.cms.futurecdn.net\/BY3RJGKxbbHd9v4nvuNmge-1024-80.png 1024w, https:\/\/cdn.mos.cms.futurecdn.net\/BY3RJGKxbbHd9v4nvuNmge-1200-80.png 1200w\" sizes=\"(min-width: 1000px) 970px, calc(100vw - 40px)\" loading=\"lazy\" src=\"https:\/\/cdn.mos.cms.futurecdn.net\/BY3RJGKxbbHd9v4nvuNmge.png\" data-pin-media=\"https:\/\/cdn.mos.cms.futurecdn.net\/BY3RJGKxbbHd9v4nvuNmge.png\"\/><\/picture><\/p>\n<\/div>\n<\/div><figcaption itemprop=\"caption description\" class=\"inline-layout\"><span class=\"credit\" itemprop=\"copyrightHolder\">(Image credit: Tom&#8217;s Hardware)<\/span><\/figcaption><\/figure>\n<p>We can also combine the arguments we used in the previous section to make multiple changes to Linux file permissions in a single command. In this section it\u2019s important not to add any extra spaces in the <em>chmod <\/em>arguments as this will cause the command to fail.<\/p>\n<p>In the first section we used <em>u <\/em>and <em>g <\/em>for<em> owner <\/em>and <em>group <\/em>and in this section we will additionally use <em>o <\/em>to target permission changes for <em>others. <\/em>Likewise, we used <em>r <\/em>and <em>w <\/em>for <em>read <\/em>and <em>write <\/em>and in this section we will add <em>x <\/em>to make changes to the executable permissions.<\/p>\n<p>1. <strong>List the directory contents<\/strong> to view the new permission settings. We should see that the permissions for <em>test1.txt<\/em> are -rw-r&#8211;r&#8211; .<\/p>\n<pre class=\"line-numbers language-bash\" language=\"bash\"><code>$ ls -l<\/code><\/pre>\n<p>2. <strong>Change the permissions so that additionally the owner can execute and the group can additionally write and execute. <\/strong>Notice that there are no spaces after the comma and also notice that you can combine <em>r,w,x <\/em>in a single argument.<\/p>\n<pre class=\"line-numbers language-bash\" language=\"bash\"><code>$ chmod u+x,g+wx test1.txt<\/code><\/pre>\n<p>3. <strong>List the directory contents to view the new permission settings.<\/strong> We should see that the permissions for <em>test1.txt<\/em> are -rwxrwxr&#8211; . This means that the <em>owner<\/em> and <em>group <\/em>can read, write and execute the file whilst others can only read.<\/p>\n<pre class=\"line-numbers language-bash\" language=\"bash\"><code>$ ls -l<\/code><\/pre>\n<h2 id=\"how-to-change-file-directory-permissions-recursively-in-linux-3\">How to Change File \/ Directory Permissions Recursively in Linux<\/h2>\n<figure class=\"van-image-figure  inline-layout\" data-bordeaux-image-check=\"\">\n<div class=\"image-full-width-wrapper\">\n<div class=\"image-widthsetter\" style=\"max-width:1572px;\">\n<p class=\"vanilla-image-block\" style=\"padding-top:95.29%;\"><picture><source type=\"image\/webp\" srcset=\"https:\/\/cdn.mos.cms.futurecdn.net\/EKeveiv5KZq8jTAPmPUo3f-320-80.png.webp 320w, https:\/\/cdn.mos.cms.futurecdn.net\/EKeveiv5KZq8jTAPmPUo3f-480-80.png.webp 480w, https:\/\/cdn.mos.cms.futurecdn.net\/EKeveiv5KZq8jTAPmPUo3f-650-80.png.webp 650w, https:\/\/cdn.mos.cms.futurecdn.net\/EKeveiv5KZq8jTAPmPUo3f-970-80.png.webp 970w, https:\/\/cdn.mos.cms.futurecdn.net\/EKeveiv5KZq8jTAPmPUo3f-1024-80.png.webp 1024w, https:\/\/cdn.mos.cms.futurecdn.net\/EKeveiv5KZq8jTAPmPUo3f-1200-80.png.webp 1200w\" sizes=\"(min-width: 1000px) 970px, calc(100vw - 40px)\"\/><img decoding=\"async\" alt=\"Change Permissions on the Linux Command Line\" class=\"expandable\" srcset=\"https:\/\/cdn.mos.cms.futurecdn.net\/EKeveiv5KZq8jTAPmPUo3f-320-80.png 320w, https:\/\/cdn.mos.cms.futurecdn.net\/EKeveiv5KZq8jTAPmPUo3f-480-80.png 480w, https:\/\/cdn.mos.cms.futurecdn.net\/EKeveiv5KZq8jTAPmPUo3f-650-80.png 650w, https:\/\/cdn.mos.cms.futurecdn.net\/EKeveiv5KZq8jTAPmPUo3f-970-80.png 970w, https:\/\/cdn.mos.cms.futurecdn.net\/EKeveiv5KZq8jTAPmPUo3f-1024-80.png 1024w, https:\/\/cdn.mos.cms.futurecdn.net\/EKeveiv5KZq8jTAPmPUo3f-1200-80.png 1200w\" sizes=\"(min-width: 1000px) 970px, calc(100vw - 40px)\" loading=\"lazy\" src=\"https:\/\/cdn.mos.cms.futurecdn.net\/EKeveiv5KZq8jTAPmPUo3f.png\" data-pin-media=\"https:\/\/cdn.mos.cms.futurecdn.net\/EKeveiv5KZq8jTAPmPUo3f.png\"\/><\/picture><\/p>\n<\/div>\n<\/div><figcaption itemprop=\"caption description\" class=\"inline-layout\"><span class=\"credit\" itemprop=\"copyrightHolder\">(Image credit: Tom&#8217;s Hardware)<\/span><\/figcaption><\/figure>\n<p>The <em>chmod <\/em>command can be used to create changes recursively to a directory meaning that changes are also applied to the files contained within the directory. Let\u2019s use what we have learnt so far and additionally use the recursive <em>-R <\/em>argument to see how this works.<\/p>\n<p>1. <strong>Move to your home directory and list the contents.<\/strong><\/p>\n<pre class=\"line-numbers language-bash\" language=\"bash\"><code>$ cd\n$ ls -l<\/code><\/pre>\n<p>We should see test_directory listed from the previous parts of this how-to. The permissions for test_directory should read drwxrwxr-x.<\/p>\n<p>2. <strong>Change the owner and group permissions of both the directory and its contents. <\/strong>Running this command will revoke owner and group write permissions for both <em>test_directory <\/em>and the file, <em>test1.txt<\/em> it contains.<\/p>\n<pre class=\"line-numbers language-bash\" language=\"bash\"><code>$ chmod -R u-w,g-w test_directory<\/code><\/pre>\n<p>3. <strong>List the home directory contents<\/strong> to check the permissions for <em>test_directory.<\/em><\/p>\n<pre class=\"line-numbers language-bash\" language=\"bash\"><code>$ ls -l\n<\/code><\/pre>\n<p>We should see that the owner and group permissions allow for reading and execution but now do not allow writing to the directory.<\/p>\n<p>4. <strong>Move into <\/strong><em><strong>test_directory<\/strong><\/em> to check permissions for<em> test1.txt.<\/em><\/p>\n<pre class=\"line-numbers language-bash\" language=\"bash\"><code>$ cd test_directory\n$ ls -l<\/code><\/pre>\n<p>We should see that the owner and group permissions for<em>test1.txt <\/em>have been changed to match the recursive changes to the host directory, removing write permissions.<\/p>\n<h2 id=\"how-to-view-your-linux-group-3\">How to View Your Linux Group<\/h2>\n<p>When we talk of users, groups and others what we mean is that our user typically belongs to a group of users. A user and group can have the same, or very different permissions. For example a team member may need more permissions to perform a certain task. The permissions that we give a user and a group will be different to what we give other users, users who are not in the group.<\/p>\n<p>We can see the groups that our user is part of via the <em>groups<\/em> command.<\/p>\n<p>1. <strong>Open a terminal and type in <\/strong><em><strong>groups<\/strong><\/em><strong>. <\/strong>This will list all of the groups available on our installation.<\/p>\n<pre class=\"line-numbers language-bash\" language=\"bash\"><code>groups<\/code><\/pre>\n<p>2. <strong>Open a terminal and type in <\/strong><em><strong>groups<\/strong><\/em><strong> followed by the user\u2019s name. <\/strong>For example here we check which groups \u201cTom\u201d belongs to and find that he belongs to the groups tom and sudo.<\/p>\n<pre class=\"line-numbers language-bash\" language=\"bash\"><code>groups tom\n<\/code><\/pre>\n<p>The output of this command looks like this.<\/p>\n<pre class=\"line-numbers language-bash\" language=\"bash\"><code>tom : tom sudo<\/code><\/pre>\n<p>Others are not a group. Rather \u201cothers\u201d refers to anyone who is not the owner, or in a group which has access to a file or directory. Typically others will only have read access to any files of directories, but this can be changed and we shall explore this later.<\/p>\n<h2 id=\"how-to-change-linux-file-permissions-with-numeric-codes-3\">How to Change Linux File Permissions With Numeric Codes<\/h2>\n<p>Though the use of r,w or x is easier to remember for Linux file permissions, many people use a series of numeric codes with chmod instead. You feed the chmod command a three-digit number and each digit applies to a different group in this order: user, group, others. So, for example, <em>chmod 777<\/em> gives all three types full read, write and execute permissions while <em>chmod 740<\/em> gives the user full permissions, the group read permissions and others no permissions at all.<\/p>\n<p>The table below shows what each number means.<\/p>\n<div id=\"slice-container-table-NTnLGkTvyDQucYwkD9ouDa-hTkC3HKKphxjCXsgMzQXFbEzQPc619wg\" class=\"slice-container table-wrapper table-NTnLGkTvyDQucYwkD9ouDa-hTkC3HKKphxjCXsgMzQXFbEzQPc619wg slice-container-table\">\n<div class=\"table__instruction\">Swipe to scroll horizontally<svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" viewbox=\"0 0 23 30\" fill=\"none\"><path d=\"M21.554 15.726a2.878 2.878 0 0 0-1.705-.374 2.881 2.881 0 0 0-1.388-3.068 2.877 2.877 0 0 0-1.992-.333 2.884 2.884 0 0 0-.1-.766 2.865 2.865 0 0 0-1.346-1.75c-.47-.27-.996-.4-1.527-.385l2.742-4.73a2.87 2.87 0 0 0 .323-.83h2.612V2.084h-2.661A2.861 2.861 0 0 0 15.18.385a2.903 2.903 0 0 0-3.952 1.055l-.373.644H2.983l1.003-1L2.99.09 1.28 1.793l-.999.995L2.99 5.484l.998-.994-1.003-.999h7.054L6.505 9.586c-.34.066-.905.186-1.523.366-1.405.41-2.321.895-2.8 1.483-.742.911-1.159 2.513-1.277 4.898l-.001.01c-.067 1.816.946 6.943.99 7.16a.688.688 0 0 0 1.35-.266c-.01-.051-1.023-5.177-.963-6.84.127-2.556.598-3.64.97-4.098.133-.163.602-.587 2.104-1.027l.206-.058-1.425 2.458a.685.685 0 0 0 .252.937c.33.19.75.077.94-.251L12.42 2.126a1.52 1.52 0 0 1 2.07-.552c.35.2.6.527.705.916.105.39.051.797-.15 1.145l-4.767 8.222a.685.685 0 0 0 .252.937c.33.19.75.077.94-.25l.794-1.368c.201-.348.529-.597.92-.702a1.508 1.508 0 0 1 1.854 1.066c.105.39.052.796-.15 1.144l-.377.652-.002.002-.898 1.55a.685.685 0 0 0 .252.938c.329.189.75.077.94-.251l.9-1.551c.201-.348.528-.597.92-.702a1.512 1.512 0 0 1 1.703 2.21l-1.223 2.11a.685.685 0 0 0 .252.938c.33.189.75.076.941-.252l.5-.862c.202-.348.529-.597.92-.702.392-.104.8-.051 1.15.15.723.416.972 1.34.554 2.06l-3.525 6.08c-.517.892-1.57 1.795-3.044 2.611-1.156.64-2.163.998-2.173 1.002a.685.685 0 0 0 .23 1.333.688.688 0 0 0 .229-.04c.18-.062 4.419-1.575 5.952-4.22l3.524-6.08a2.878 2.878 0 0 0-1.059-3.934Z\" fill=\"#333\"\/><\/svg><\/div>\n<div class=\"table__container\">\n<table tabindex=\"0\" class=\"table__wrapper table__wrapper--inbodyContent table__wrapper--sticky table__wrapper--divider\">\n<thead class=\"table__head\">\n<tr class=\"table__head__row\">\n<th class=\"table__head__heading table__head__heading--left\" colspan=\"1\">\n<p>Number<\/p>\n<\/th>\n<th class=\"table__head__heading table__head__heading--left\" colspan=\"1\">\n<p>Permissions<\/p>\n<\/th>\n<\/tr>\n<\/thead>\n<tbody class=\"table__body\">\n<tr class=\"table__body__row\">\n<td class=\"table_body__data\" colspan=\"1\" style=\"text-align:left\">\n<p>0<\/p>\n<\/td>\n<td class=\"table_body__data\" colspan=\"1\" style=\"text-align:left\">\n<p>None<\/p>\n<\/td>\n<\/tr>\n<tr class=\"table__body__row\">\n<td class=\"table_body__data\" colspan=\"1\" style=\"text-align:left\">\n<p>1<\/p>\n<\/td>\n<td class=\"table_body__data\" colspan=\"1\" style=\"text-align:left\">\n<p>Execute<\/p>\n<\/td>\n<\/tr>\n<tr class=\"table__body__row\">\n<td class=\"table_body__data\" colspan=\"1\" style=\"text-align:left\">\n<p>2<\/p>\n<\/td>\n<td class=\"table_body__data\" colspan=\"1\" style=\"text-align:left\">\n<p>Write\u00a0<\/p>\n<\/td>\n<\/tr>\n<tr class=\"table__body__row\">\n<td class=\"table_body__data\" colspan=\"1\" style=\"text-align:left\">\n<p>3<\/p>\n<\/td>\n<td class=\"table_body__data\" colspan=\"1\" style=\"text-align:left\">\n<p>Execute and Write\u00a0<\/p>\n<\/td>\n<\/tr>\n<tr class=\"table__body__row\">\n<td class=\"table_body__data\" colspan=\"1\" style=\"text-align:left\">\n<p>4<\/p>\n<\/td>\n<td class=\"table_body__data\" colspan=\"1\" style=\"text-align:left\">\n<p>Read<\/p>\n<\/td>\n<\/tr>\n<tr class=\"table__body__row\">\n<td class=\"table_body__data\" colspan=\"1\" style=\"text-align:left\">\n<p>5<\/p>\n<\/td>\n<td class=\"table_body__data\" colspan=\"1\" style=\"text-align:left\">\n<p>Read and Execute<\/p>\n<\/td>\n<\/tr>\n<tr class=\"table__body__row\">\n<td class=\"table_body__data\" colspan=\"1\" style=\"text-align:left\">\n<p>6<\/p>\n<\/td>\n<td class=\"table_body__data\" colspan=\"1\" style=\"text-align:left\">\n<p>Read and Write<\/p>\n<\/td>\n<\/tr>\n<tr class=\"table__body__row\">\n<td class=\"table_body__data\" colspan=\"1\" style=\"text-align:left\">\n<p>7<\/p>\n<\/td>\n<td class=\"table_body__data\" colspan=\"1\" style=\"text-align:left\">\n<p>All: Read, Write and Execute<\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<p>With these basic usages of the <em>chmod <\/em>command you get a lot of control over file and directory permissions. There are lots of different arguments to add to <em>chmod <\/em>that allow you to work with different approaches.<\/p>\n<p>For example it\u2019s worth researching the use of <em>= <\/em>instead of + and \u2013 as, rather than toggling permissions on and off, you can define permissions directly for some or all users. As you research and learn about <em>chmod <\/em>it\u2019s worth remembering to practice on test files and directories as it can be frustrating if you accidentally remove all permissions on a file you depend on.<\/p>\n<\/div>\n<div id=\"article-body\">\n<p>If you\u2019ve ever tried to run a script from the command line in Linux and gotten an error message saying that it\u2019s not executable or attempted to enter a directory only to be blocked by the system, you probably don\u2019t have permissions to do those things. Fortunately, if you have the proper rights or the ability to act as a super user (accessible by using sudo), you can change the permissions on files and directories.<\/p>\n<p>In this how-to we\u2019ll look at the<em> chmod <\/em>command, a powerful command that can change file and directory permissions for the owner, user group members and others. In a section below, we\u2019ll also explain how to tell what group your user is in and exactly what Linux means by \u201cothers.\u201d<\/p>\n<aside data-block-type=\"embed\" data-render-type=\"fte\" data-skip=\"dealsy\" data-widget-type=\"seasonal\" class=\"hawk-base\"\/>\n<p>Whilst you become accustomed to these commands it\u2019s good to work with example empty files and directories and you should take extra care to ensure you are carefully following the instructions.<\/p>\n<aside data-component-name=\"Recirculation:ArticleRiver\" data-nosnippet=\"\">\n<span class=\"bg-secondary-500 text-white text-lg font-bold uppercase py-1 px-2 leading-[1.625rem] sm:leading-[6px] sm:text-sm\"><br \/>\nYou may like<br \/>\n<\/span><\/p>\n<\/aside>\n<p>All the commands in this how-to will work on most Linux machines. We\u2019ve used an Ubuntu LTS install but you could run this how-to on a<a data-analytics-id=\"inline-link\" href=\"https:\/\/www.tomshardware.com\/news\/raspberry-pi\" data-before-rewrite-localise=\"https:\/\/www.tomshardware.com\/news\/raspberry-pi\"> <u>Raspberry Pi<\/u><\/a>. All of the how-to is performed via the Terminal. You can open a terminal window on most Linux machines by pressing <em>ctrl, alt <\/em>and <em>t.<\/em><\/p>\n<h2 id=\"how-to-check-file-permissions-in-linux-3\">How to Check File Permissions in Linux<\/h2>\n<figure class=\"van-image-figure  inline-layout\" data-bordeaux-image-check=\"\">\n<div class=\"image-full-width-wrapper\">\n<div class=\"image-widthsetter\" style=\"max-width:1572px;\">\n<p class=\"vanilla-image-block\" style=\"padding-top:67.81%;\"><picture><source type=\"image\/webp\" srcset=\"https:\/\/cdn.mos.cms.futurecdn.net\/ekbk7JuautTKnAECmHtBYe-320-80.png.webp 320w, https:\/\/cdn.mos.cms.futurecdn.net\/ekbk7JuautTKnAECmHtBYe-480-80.png.webp 480w, https:\/\/cdn.mos.cms.futurecdn.net\/ekbk7JuautTKnAECmHtBYe-650-80.png.webp 650w, https:\/\/cdn.mos.cms.futurecdn.net\/ekbk7JuautTKnAECmHtBYe-970-80.png.webp 970w, https:\/\/cdn.mos.cms.futurecdn.net\/ekbk7JuautTKnAECmHtBYe-1024-80.png.webp 1024w, https:\/\/cdn.mos.cms.futurecdn.net\/ekbk7JuautTKnAECmHtBYe-1200-80.png.webp 1200w\" sizes=\"(min-width: 1000px) 970px, calc(100vw - 40px)\"\/><img decoding=\"async\" alt=\"Change Permissions on the Linux Command Line\" class=\"expandable\" srcset=\"https:\/\/cdn.mos.cms.futurecdn.net\/ekbk7JuautTKnAECmHtBYe-320-80.png 320w, https:\/\/cdn.mos.cms.futurecdn.net\/ekbk7JuautTKnAECmHtBYe-480-80.png 480w, https:\/\/cdn.mos.cms.futurecdn.net\/ekbk7JuautTKnAECmHtBYe-650-80.png 650w, https:\/\/cdn.mos.cms.futurecdn.net\/ekbk7JuautTKnAECmHtBYe-970-80.png 970w, https:\/\/cdn.mos.cms.futurecdn.net\/ekbk7JuautTKnAECmHtBYe-1024-80.png 1024w, https:\/\/cdn.mos.cms.futurecdn.net\/ekbk7JuautTKnAECmHtBYe-1200-80.png 1200w\" sizes=\"(min-width: 1000px) 970px, calc(100vw - 40px)\" loading=\"lazy\" src=\"https:\/\/cdn.mos.cms.futurecdn.net\/ekbk7JuautTKnAECmHtBYe.png\" data-pin-media=\"https:\/\/cdn.mos.cms.futurecdn.net\/ekbk7JuautTKnAECmHtBYe.png\"\/><\/picture><\/p>\n<\/div>\n<\/div><figcaption itemprop=\"caption description\" class=\"inline-layout\"><span class=\"credit\" itemprop=\"copyrightHolder\">(Image credit: Tom&#8217;s Hardware)<\/span><\/figcaption><\/figure>\n<p>To begin, let&#8217;s create a test file in a test directory and take a look at its default permissions. To see the permissions we will use <em>ls <\/em>with the <em>-l<\/em> argument added.<\/p>\n<p>1. <strong>Create a new directory called <\/strong><em><strong>test_directory<\/strong><\/em><\/p>\n<pre class=\"line-numbers language-bash\" language=\"bash\"><code>$ mkdir test_directory<\/code><\/pre>\n<p>2. <strong>Move into the newly created directory<\/strong>.<\/p>\n<div id=\"slice-container-newsletterForm-articleInbodyContent-NTnLGkTvyDQucYwkD9ouDa\" class=\"slice-container newsletter-inbodyContent-slice newsletterForm-articleInbodyContent-NTnLGkTvyDQucYwkD9ouDa slice-container-newsletterForm\">\n<div data-hydrate=\"true\" class=\"newsletter-form__wrapper newsletter-form__wrapper--inbodyContent\">\n<div class=\"newsletter-form__container\">\n<section class=\"newsletter-form__top-bar\"\/>\n<section class=\"newsletter-form__main-section\">\n<p class=\"newsletter-form__strapline\">Get Tom&#8217;s Hardware&#8217;s best news and in-depth reviews, straight to your inbox.<\/p>\n<\/section>\n<\/div>\n<\/div>\n<\/div>\n<pre class=\"line-numbers language-bash\" language=\"bash\"><code>$ cd test_directory<\/code><\/pre>\n<p>3. <strong>Create a new test file called <\/strong><em><strong>test1.txt<\/strong><\/em><strong>.<\/strong><\/p>\n<pre class=\"line-numbers language-bash\" language=\"bash\"><code>$ touch test1.txt<\/code><\/pre>\n<p>4. <strong>List the contents of the directory using <\/strong><em><strong>ls -l<\/strong><\/em><strong>.<\/strong><\/p>\n<pre class=\"line-numbers language-bash\" language=\"bash\"><code>$ ls -l<\/code><\/pre>\n<p>Using <em>ls -l<\/em> gives us a lot more information about the items returned on the list. We should see that<em> test1.txt<\/em> has been created. We are interested in the first 10 characters on the listing which for our test file read <em>&#8211; rw- rw- r&#8211;<\/em>.<\/p>\n<p>The first \u2013 indicates that the object on the list is a file. If we ran<em> ls -l<\/em> and a directory was listed this first character would be a<em> d<\/em>. The next 9 characters are arranged in 3 sets of 3.<\/p>\n<p>The first set of 3 refers to the owner, the second set of 3 refer to user groups and the final set of three refer to others. Each set of 3 characters can contain either \u2013 or r, w, and x. If you can see an r in the set then that set has read permissions granted. If you can see a w that set can write to a file and if you can see an x in the set then that set can execute the file as a script or program.<\/p>\n<p>We can see that our <em>test1.txt <\/em>currently has the owner and group member permissions set to read and write with others only allowed to read. No one has permission to execute the file.<\/p>\n<h2 id=\"how-to-change-linux-file-directory-permissions-quickly-3\">How to Change Linux File \/ Directory Permissions Quickly<\/h2>\n<figure class=\"van-image-figure  inline-layout\" data-bordeaux-image-check=\"\">\n<div class=\"image-full-width-wrapper\">\n<div class=\"image-widthsetter\" style=\"max-width:1572px;\">\n<p class=\"vanilla-image-block\" style=\"padding-top:67.81%;\"><picture><source type=\"image\/webp\" srcset=\"https:\/\/cdn.mos.cms.futurecdn.net\/FPvjdEzu6XTFPABMr9J9pe-320-80.png.webp 320w, https:\/\/cdn.mos.cms.futurecdn.net\/FPvjdEzu6XTFPABMr9J9pe-480-80.png.webp 480w, https:\/\/cdn.mos.cms.futurecdn.net\/FPvjdEzu6XTFPABMr9J9pe-650-80.png.webp 650w, https:\/\/cdn.mos.cms.futurecdn.net\/FPvjdEzu6XTFPABMr9J9pe-970-80.png.webp 970w, https:\/\/cdn.mos.cms.futurecdn.net\/FPvjdEzu6XTFPABMr9J9pe-1024-80.png.webp 1024w, https:\/\/cdn.mos.cms.futurecdn.net\/FPvjdEzu6XTFPABMr9J9pe-1200-80.png.webp 1200w\" sizes=\"(min-width: 1000px) 970px, calc(100vw - 40px)\"\/><img decoding=\"async\" alt=\"Change Permissions on the Linux Command Line\" class=\"expandable\" srcset=\"https:\/\/cdn.mos.cms.futurecdn.net\/FPvjdEzu6XTFPABMr9J9pe-320-80.png 320w, https:\/\/cdn.mos.cms.futurecdn.net\/FPvjdEzu6XTFPABMr9J9pe-480-80.png 480w, https:\/\/cdn.mos.cms.futurecdn.net\/FPvjdEzu6XTFPABMr9J9pe-650-80.png 650w, https:\/\/cdn.mos.cms.futurecdn.net\/FPvjdEzu6XTFPABMr9J9pe-970-80.png 970w, https:\/\/cdn.mos.cms.futurecdn.net\/FPvjdEzu6XTFPABMr9J9pe-1024-80.png 1024w, https:\/\/cdn.mos.cms.futurecdn.net\/FPvjdEzu6XTFPABMr9J9pe-1200-80.png 1200w\" sizes=\"(min-width: 1000px) 970px, calc(100vw - 40px)\" loading=\"lazy\" src=\"https:\/\/cdn.mos.cms.futurecdn.net\/FPvjdEzu6XTFPABMr9J9pe.png\" data-pin-media=\"https:\/\/cdn.mos.cms.futurecdn.net\/FPvjdEzu6XTFPABMr9J9pe.png\"\/><\/picture><\/p>\n<\/div>\n<\/div><figcaption itemprop=\"caption description\" class=\"inline-layout\"><span class=\"credit\" itemprop=\"copyrightHolder\">(Image credit: Tom&#8217;s Hardware)<\/span><\/figcaption><\/figure>\n<p>We can use the <em>chmod <\/em>command to toggle the read, write and execute permissions on and off for the owner, group and others. Let\u2019s begin with changing single permissions for the owner and group.<\/p>\n<p>1. In the <em>test_directory,<\/em> <strong>list the current permissions for <\/strong><em><strong>test1.txt<\/strong><\/em><strong>.<\/strong><\/p>\n<pre class=\"line-numbers language-bash\" language=\"bash\"><code>$ ls -l<\/code><\/pre>\n<p>These should be unchanged from when we created <em>test1.txt <\/em>and should read <em>-rw-rw-r&#8211; .<\/em><\/p>\n<p>2. <strong>Change the permission of the owner to read only<\/strong>.<\/p>\n<pre class=\"line-numbers language-bash\" language=\"bash\"><code>$ chmod u-w test1.txt<\/code><\/pre>\n<p>3. <strong>List the directory contents<\/strong> to view the new permission settings. We should now see that the permissions for <em>test1.txt <\/em>read -r&#8211;rw-r&#8211; indicating that, for the owner, the file is now read only.<\/p>\n<pre class=\"line-numbers language-bash\" language=\"bash\"><code>$ ls -l<\/code><\/pre>\n<p>4. <strong>Change  permission of groups to read only. <\/strong>Similar to changing permissions for the owner we can change permission settings for the groups. To revoke write permissions we can use the argument <em>g-w<\/em>.<\/p>\n<pre class=\"line-numbers language-bash\" language=\"bash\"><code>$ chmod g-w test1.txt<\/code><\/pre>\n<p>5. <strong>List the directory contents <\/strong>to view the new permission settings<strong>.<\/strong><\/p>\n<pre class=\"line-numbers language-bash\" language=\"bash\"><code>$ ls -l<\/code><\/pre>\n<p>We should now see that the permissions for <em>test1.txt <\/em>read -r&#8211;r&#8211;r&#8211; indicating that, for the groups, the file is now read only.<\/p>\n<p>6. <strong>Enable write permissions for the owner. <\/strong>Instead of using <em>u-w <\/em>to remove write permissions we can intuitively use <em>u+w <\/em>to grant write permissions for the owner.<\/p>\n<pre class=\"line-numbers language-bash\" language=\"bash\"><code>$ chmod u+w test1.txt<\/code><\/pre>\n<p>7. <strong>List the directory contents <\/strong>to view the new permission settings. We should now see that the permissions for <em>test1.txt <\/em>read -rw-r&#8211;r&#8211; indicating that, for the owner, write permissions have been granted.<\/p>\n<pre class=\"line-numbers language-bash\" language=\"bash\"><code>$ ls -l<\/code><\/pre>\n<h2 id=\"how-to-apply-multiple-file-directory-permission-changes-in-linux-3\">How to Apply Multiple File \/ Directory Permission Changes in Linux<\/h2>\n<figure class=\"van-image-figure  inline-layout\" data-bordeaux-image-check=\"\">\n<div class=\"image-full-width-wrapper\">\n<div class=\"image-widthsetter\" style=\"max-width:1572px;\">\n<p class=\"vanilla-image-block\" style=\"padding-top:67.81%;\"><picture><source type=\"image\/webp\" srcset=\"https:\/\/cdn.mos.cms.futurecdn.net\/BY3RJGKxbbHd9v4nvuNmge-320-80.png.webp 320w, https:\/\/cdn.mos.cms.futurecdn.net\/BY3RJGKxbbHd9v4nvuNmge-480-80.png.webp 480w, https:\/\/cdn.mos.cms.futurecdn.net\/BY3RJGKxbbHd9v4nvuNmge-650-80.png.webp 650w, https:\/\/cdn.mos.cms.futurecdn.net\/BY3RJGKxbbHd9v4nvuNmge-970-80.png.webp 970w, https:\/\/cdn.mos.cms.futurecdn.net\/BY3RJGKxbbHd9v4nvuNmge-1024-80.png.webp 1024w, https:\/\/cdn.mos.cms.futurecdn.net\/BY3RJGKxbbHd9v4nvuNmge-1200-80.png.webp 1200w\" sizes=\"(min-width: 1000px) 970px, calc(100vw - 40px)\"\/><img decoding=\"async\" alt=\"Change Permissions on the Linux Command Line\" class=\"expandable\" srcset=\"https:\/\/cdn.mos.cms.futurecdn.net\/BY3RJGKxbbHd9v4nvuNmge-320-80.png 320w, https:\/\/cdn.mos.cms.futurecdn.net\/BY3RJGKxbbHd9v4nvuNmge-480-80.png 480w, https:\/\/cdn.mos.cms.futurecdn.net\/BY3RJGKxbbHd9v4nvuNmge-650-80.png 650w, https:\/\/cdn.mos.cms.futurecdn.net\/BY3RJGKxbbHd9v4nvuNmge-970-80.png 970w, https:\/\/cdn.mos.cms.futurecdn.net\/BY3RJGKxbbHd9v4nvuNmge-1024-80.png 1024w, https:\/\/cdn.mos.cms.futurecdn.net\/BY3RJGKxbbHd9v4nvuNmge-1200-80.png 1200w\" sizes=\"(min-width: 1000px) 970px, calc(100vw - 40px)\" loading=\"lazy\" src=\"https:\/\/cdn.mos.cms.futurecdn.net\/BY3RJGKxbbHd9v4nvuNmge.png\" data-pin-media=\"https:\/\/cdn.mos.cms.futurecdn.net\/BY3RJGKxbbHd9v4nvuNmge.png\"\/><\/picture><\/p>\n<\/div>\n<\/div><figcaption itemprop=\"caption description\" class=\"inline-layout\"><span class=\"credit\" itemprop=\"copyrightHolder\">(Image credit: Tom&#8217;s Hardware)<\/span><\/figcaption><\/figure>\n<p>We can also combine the arguments we used in the previous section to make multiple changes to Linux file permissions in a single command. In this section it\u2019s important not to add any extra spaces in the <em>chmod <\/em>arguments as this will cause the command to fail.<\/p>\n<p>In the first section we used <em>u <\/em>and <em>g <\/em>for<em> owner <\/em>and <em>group <\/em>and in this section we will additionally use <em>o <\/em>to target permission changes for <em>others. <\/em>Likewise, we used <em>r <\/em>and <em>w <\/em>for <em>read <\/em>and <em>write <\/em>and in this section we will add <em>x <\/em>to make changes to the executable permissions.<\/p>\n<p>1. <strong>List the directory contents<\/strong> to view the new permission settings. We should see that the permissions for <em>test1.txt<\/em> are -rw-r&#8211;r&#8211; .<\/p>\n<pre class=\"line-numbers language-bash\" language=\"bash\"><code>$ ls -l<\/code><\/pre>\n<p>2. <strong>Change the permissions so that additionally the owner can execute and the group can additionally write and execute. <\/strong>Notice that there are no spaces after the comma and also notice that you can combine <em>r,w,x <\/em>in a single argument.<\/p>\n<pre class=\"line-numbers language-bash\" language=\"bash\"><code>$ chmod u+x,g+wx test1.txt<\/code><\/pre>\n<p>3. <strong>List the directory contents to view the new permission settings.<\/strong> We should see that the permissions for <em>test1.txt<\/em> are -rwxrwxr&#8211; . This means that the <em>owner<\/em> and <em>group <\/em>can read, write and execute the file whilst others can only read.<\/p>\n<pre class=\"line-numbers language-bash\" language=\"bash\"><code>$ ls -l<\/code><\/pre>\n<h2 id=\"how-to-change-file-directory-permissions-recursively-in-linux-3\">How to Change File \/ Directory Permissions Recursively in Linux<\/h2>\n<figure class=\"van-image-figure  inline-layout\" data-bordeaux-image-check=\"\">\n<div class=\"image-full-width-wrapper\">\n<div class=\"image-widthsetter\" style=\"max-width:1572px;\">\n<p class=\"vanilla-image-block\" style=\"padding-top:95.29%;\"><picture><source type=\"image\/webp\" srcset=\"https:\/\/cdn.mos.cms.futurecdn.net\/EKeveiv5KZq8jTAPmPUo3f-320-80.png.webp 320w, https:\/\/cdn.mos.cms.futurecdn.net\/EKeveiv5KZq8jTAPmPUo3f-480-80.png.webp 480w, https:\/\/cdn.mos.cms.futurecdn.net\/EKeveiv5KZq8jTAPmPUo3f-650-80.png.webp 650w, https:\/\/cdn.mos.cms.futurecdn.net\/EKeveiv5KZq8jTAPmPUo3f-970-80.png.webp 970w, https:\/\/cdn.mos.cms.futurecdn.net\/EKeveiv5KZq8jTAPmPUo3f-1024-80.png.webp 1024w, https:\/\/cdn.mos.cms.futurecdn.net\/EKeveiv5KZq8jTAPmPUo3f-1200-80.png.webp 1200w\" sizes=\"(min-width: 1000px) 970px, calc(100vw - 40px)\"\/><img decoding=\"async\" alt=\"Change Permissions on the Linux Command Line\" class=\"expandable\" srcset=\"https:\/\/cdn.mos.cms.futurecdn.net\/EKeveiv5KZq8jTAPmPUo3f-320-80.png 320w, https:\/\/cdn.mos.cms.futurecdn.net\/EKeveiv5KZq8jTAPmPUo3f-480-80.png 480w, https:\/\/cdn.mos.cms.futurecdn.net\/EKeveiv5KZq8jTAPmPUo3f-650-80.png 650w, https:\/\/cdn.mos.cms.futurecdn.net\/EKeveiv5KZq8jTAPmPUo3f-970-80.png 970w, https:\/\/cdn.mos.cms.futurecdn.net\/EKeveiv5KZq8jTAPmPUo3f-1024-80.png 1024w, https:\/\/cdn.mos.cms.futurecdn.net\/EKeveiv5KZq8jTAPmPUo3f-1200-80.png 1200w\" sizes=\"(min-width: 1000px) 970px, calc(100vw - 40px)\" loading=\"lazy\" src=\"https:\/\/cdn.mos.cms.futurecdn.net\/EKeveiv5KZq8jTAPmPUo3f.png\" data-pin-media=\"https:\/\/cdn.mos.cms.futurecdn.net\/EKeveiv5KZq8jTAPmPUo3f.png\"\/><\/picture><\/p>\n<\/div>\n<\/div><figcaption itemprop=\"caption description\" class=\"inline-layout\"><span class=\"credit\" itemprop=\"copyrightHolder\">(Image credit: Tom&#8217;s Hardware)<\/span><\/figcaption><\/figure>\n<p>The <em>chmod <\/em>command can be used to create changes recursively to a directory meaning that changes are also applied to the files contained within the directory. Let\u2019s use what we have learnt so far and additionally use the recursive <em>-R <\/em>argument to see how this works.<\/p>\n<p>1. <strong>Move to your home directory and list the contents.<\/strong><\/p>\n<pre class=\"line-numbers language-bash\" language=\"bash\"><code>$ cd\n$ ls -l<\/code><\/pre>\n<p>We should see test_directory listed from the previous parts of this how-to. The permissions for test_directory should read drwxrwxr-x.<\/p>\n<p>2. <strong>Change the owner and group permissions of both the directory and its contents. <\/strong>Running this command will revoke owner and group write permissions for both <em>test_directory <\/em>and the file, <em>test1.txt<\/em> it contains.<\/p>\n<pre class=\"line-numbers language-bash\" language=\"bash\"><code>$ chmod -R u-w,g-w test_directory<\/code><\/pre>\n<p>3. <strong>List the home directory contents<\/strong> to check the permissions for <em>test_directory.<\/em><\/p>\n<pre class=\"line-numbers language-bash\" language=\"bash\"><code>$ ls -l\n<\/code><\/pre>\n<p>We should see that the owner and group permissions allow for reading and execution but now do not allow writing to the directory.<\/p>\n<p>4. <strong>Move into <\/strong><em><strong>test_directory<\/strong><\/em> to check permissions for<em> test1.txt.<\/em><\/p>\n<pre class=\"line-numbers language-bash\" language=\"bash\"><code>$ cd test_directory\n$ ls -l<\/code><\/pre>\n<p>We should see that the owner and group permissions for<em>test1.txt <\/em>have been changed to match the recursive changes to the host directory, removing write permissions.<\/p>\n<h2 id=\"how-to-view-your-linux-group-3\">How to View Your Linux Group<\/h2>\n<p>When we talk of users, groups and others what we mean is that our user typically belongs to a group of users. A user and group can have the same, or very different permissions. For example a team member may need more permissions to perform a certain task. The permissions that we give a user and a group will be different to what we give other users, users who are not in the group.<\/p>\n<p>We can see the groups that our user is part of via the <em>groups<\/em> command.<\/p>\n<p>1. <strong>Open a terminal and type in <\/strong><em><strong>groups<\/strong><\/em><strong>. <\/strong>This will list all of the groups available on our installation.<\/p>\n<pre class=\"line-numbers language-bash\" language=\"bash\"><code>groups<\/code><\/pre>\n<p>2. <strong>Open a terminal and type in <\/strong><em><strong>groups<\/strong><\/em><strong> followed by the user\u2019s name. <\/strong>For example here we check which groups \u201cTom\u201d belongs to and find that he belongs to the groups tom and sudo.<\/p>\n<pre class=\"line-numbers language-bash\" language=\"bash\"><code>groups tom\n<\/code><\/pre>\n<p>The output of this command looks like this.<\/p>\n<pre class=\"line-numbers language-bash\" language=\"bash\"><code>tom : tom sudo<\/code><\/pre>\n<p>Others are not a group. Rather \u201cothers\u201d refers to anyone who is not the owner, or in a group which has access to a file or directory. Typically others will only have read access to any files of directories, but this can be changed and we shall explore this later.<\/p>\n<h2 id=\"how-to-change-linux-file-permissions-with-numeric-codes-3\">How to Change Linux File Permissions With Numeric Codes<\/h2>\n<p>Though the use of r,w or x is easier to remember for Linux file permissions, many people use a series of numeric codes with chmod instead. You feed the chmod command a three-digit number and each digit applies to a different group in this order: user, group, others. So, for example, <em>chmod 777<\/em> gives all three types full read, write and execute permissions while <em>chmod 740<\/em> gives the user full permissions, the group read permissions and others no permissions at all.<\/p>\n<p>The table below shows what each number means.<\/p>\n<div id=\"slice-container-table-NTnLGkTvyDQucYwkD9ouDa-hTkC3HKKphxjCXsgMzQXFbEzQPc619wg\" class=\"slice-container table-wrapper table-NTnLGkTvyDQucYwkD9ouDa-hTkC3HKKphxjCXsgMzQXFbEzQPc619wg slice-container-table\">\n<div class=\"table__instruction\">Swipe to scroll horizontally<svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" viewbox=\"0 0 23 30\" fill=\"none\"><path d=\"M21.554 15.726a2.878 2.878 0 0 0-1.705-.374 2.881 2.881 0 0 0-1.388-3.068 2.877 2.877 0 0 0-1.992-.333 2.884 2.884 0 0 0-.1-.766 2.865 2.865 0 0 0-1.346-1.75c-.47-.27-.996-.4-1.527-.385l2.742-4.73a2.87 2.87 0 0 0 .323-.83h2.612V2.084h-2.661A2.861 2.861 0 0 0 15.18.385a2.903 2.903 0 0 0-3.952 1.055l-.373.644H2.983l1.003-1L2.99.09 1.28 1.793l-.999.995L2.99 5.484l.998-.994-1.003-.999h7.054L6.505 9.586c-.34.066-.905.186-1.523.366-1.405.41-2.321.895-2.8 1.483-.742.911-1.159 2.513-1.277 4.898l-.001.01c-.067 1.816.946 6.943.99 7.16a.688.688 0 0 0 1.35-.266c-.01-.051-1.023-5.177-.963-6.84.127-2.556.598-3.64.97-4.098.133-.163.602-.587 2.104-1.027l.206-.058-1.425 2.458a.685.685 0 0 0 .252.937c.33.19.75.077.94-.251L12.42 2.126a1.52 1.52 0 0 1 2.07-.552c.35.2.6.527.705.916.105.39.051.797-.15 1.145l-4.767 8.222a.685.685 0 0 0 .252.937c.33.19.75.077.94-.25l.794-1.368c.201-.348.529-.597.92-.702a1.508 1.508 0 0 1 1.854 1.066c.105.39.052.796-.15 1.144l-.377.652-.002.002-.898 1.55a.685.685 0 0 0 .252.938c.329.189.75.077.94-.251l.9-1.551c.201-.348.528-.597.92-.702a1.512 1.512 0 0 1 1.703 2.21l-1.223 2.11a.685.685 0 0 0 .252.938c.33.189.75.076.941-.252l.5-.862c.202-.348.529-.597.92-.702.392-.104.8-.051 1.15.15.723.416.972 1.34.554 2.06l-3.525 6.08c-.517.892-1.57 1.795-3.044 2.611-1.156.64-2.163.998-2.173 1.002a.685.685 0 0 0 .23 1.333.688.688 0 0 0 .229-.04c.18-.062 4.419-1.575 5.952-4.22l3.524-6.08a2.878 2.878 0 0 0-1.059-3.934Z\" fill=\"#333\"\/><\/svg><\/div>\n<div class=\"table__container\">\n<table tabindex=\"0\" class=\"table__wrapper table__wrapper--inbodyContent table__wrapper--sticky table__wrapper--divider\">\n<thead class=\"table__head\">\n<tr class=\"table__head__row\">\n<th class=\"table__head__heading table__head__heading--left\" colspan=\"1\">\n<p>Number<\/p>\n<\/th>\n<th class=\"table__head__heading table__head__heading--left\" colspan=\"1\">\n<p>Permissions<\/p>\n<\/th>\n<\/tr>\n<\/thead>\n<tbody class=\"table__body\">\n<tr class=\"table__body__row\">\n<td class=\"table_body__data\" colspan=\"1\" style=\"text-align:left\">\n<p>0<\/p>\n<\/td>\n<td class=\"table_body__data\" colspan=\"1\" style=\"text-align:left\">\n<p>None<\/p>\n<\/td>\n<\/tr>\n<tr class=\"table__body__row\">\n<td class=\"table_body__data\" colspan=\"1\" style=\"text-align:left\">\n<p>1<\/p>\n<\/td>\n<td class=\"table_body__data\" colspan=\"1\" style=\"text-align:left\">\n<p>Execute<\/p>\n<\/td>\n<\/tr>\n<tr class=\"table__body__row\">\n<td class=\"table_body__data\" colspan=\"1\" style=\"text-align:left\">\n<p>2<\/p>\n<\/td>\n<td class=\"table_body__data\" colspan=\"1\" style=\"text-align:left\">\n<p>Write\u00a0<\/p>\n<\/td>\n<\/tr>\n<tr class=\"table__body__row\">\n<td class=\"table_body__data\" colspan=\"1\" style=\"text-align:left\">\n<p>3<\/p>\n<\/td>\n<td class=\"table_body__data\" colspan=\"1\" style=\"text-align:left\">\n<p>Execute and Write\u00a0<\/p>\n<\/td>\n<\/tr>\n<tr class=\"table__body__row\">\n<td class=\"table_body__data\" colspan=\"1\" style=\"text-align:left\">\n<p>4<\/p>\n<\/td>\n<td class=\"table_body__data\" colspan=\"1\" style=\"text-align:left\">\n<p>Read<\/p>\n<\/td>\n<\/tr>\n<tr class=\"table__body__row\">\n<td class=\"table_body__data\" colspan=\"1\" style=\"text-align:left\">\n<p>5<\/p>\n<\/td>\n<td class=\"table_body__data\" colspan=\"1\" style=\"text-align:left\">\n<p>Read and Execute<\/p>\n<\/td>\n<\/tr>\n<tr class=\"table__body__row\">\n<td class=\"table_body__data\" colspan=\"1\" style=\"text-align:left\">\n<p>6<\/p>\n<\/td>\n<td class=\"table_body__data\" colspan=\"1\" style=\"text-align:left\">\n<p>Read and Write<\/p>\n<\/td>\n<\/tr>\n<tr class=\"table__body__row\">\n<td class=\"table_body__data\" colspan=\"1\" style=\"text-align:left\">\n<p>7<\/p>\n<\/td>\n<td class=\"table_body__data\" colspan=\"1\" style=\"text-align:left\">\n<p>All: Read, Write and Execute<\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<p>With these basic usages of the <em>chmod <\/em>command you get a lot of control over file and directory permissions. There are lots of different arguments to add to <em>chmod <\/em>that allow you to work with different approaches.<\/p>\n<p>For example it\u2019s worth researching the use of <em>= <\/em>instead of + and \u2013 as, rather than toggling permissions on and off, you can define permissions directly for some or all users. As you research and learn about <em>chmod <\/em>it\u2019s worth remembering to practice on test files and directories as it can be frustrating if you accidentally remove all permissions on a file you depend on.<\/p>\n<\/div>\n<p>[\/gpt3]<br \/>\n<br \/><\/p>\n<div id=\"article-body\">\n<p>If you\u2019ve ever tried to run a script from the command line in Linux and gotten an error message saying that it\u2019s not executable or attempted to enter a directory only to be blocked by the system, you probably don\u2019t have permissions to do those things. Fortunately, if you have the proper rights or the ability to act as a super user (accessible by using sudo), you can change the permissions on files and directories.<\/p>\n<p>In this how-to we\u2019ll look at the<em> chmod <\/em>command, a powerful command that can change file and directory permissions for the owner, user group members and others. In a section below, we\u2019ll also explain how to tell what group your user is in and exactly what Linux means by \u201cothers.\u201d<\/p>\n<aside data-block-type=\"embed\" data-render-type=\"fte\" data-skip=\"dealsy\" data-widget-type=\"seasonal\" class=\"hawk-base\"\/>\n<p>Whilst you become accustomed to these commands it\u2019s good to work with example empty files and directories and you should take extra care to ensure you are carefully following the instructions.<\/p>\n<aside data-component-name=\"Recirculation:ArticleRiver\" data-nosnippet=\"\">\n<span class=\"bg-secondary-500 text-white text-lg font-bold uppercase py-1 px-2 leading-[1.625rem] sm:leading-[6px] sm:text-sm\"><br \/>\nYou may like<br \/>\n<\/span><\/p>\n<\/aside>\n<p>All the commands in this how-to will work on most Linux machines. We\u2019ve used an Ubuntu LTS install but you could run this how-to on a<a data-analytics-id=\"inline-link\" href=\"https:\/\/www.tomshardware.com\/news\/raspberry-pi\" data-before-rewrite-localise=\"https:\/\/www.tomshardware.com\/news\/raspberry-pi\"> <u>Raspberry Pi<\/u><\/a>. All of the how-to is performed via the Terminal. You can open a terminal window on most Linux machines by pressing <em>ctrl, alt <\/em>and <em>t.<\/em><\/p>\n<h2 id=\"how-to-check-file-permissions-in-linux-3\">How to Check File Permissions in Linux<\/h2>\n<figure class=\"van-image-figure  inline-layout\" data-bordeaux-image-check=\"\">\n<div class=\"image-full-width-wrapper\">\n<div class=\"image-widthsetter\" style=\"max-width:1572px;\">\n<p class=\"vanilla-image-block\" style=\"padding-top:67.81%;\"><picture><source type=\"image\/webp\" srcset=\"https:\/\/cdn.mos.cms.futurecdn.net\/ekbk7JuautTKnAECmHtBYe-320-80.png.webp 320w, https:\/\/cdn.mos.cms.futurecdn.net\/ekbk7JuautTKnAECmHtBYe-480-80.png.webp 480w, https:\/\/cdn.mos.cms.futurecdn.net\/ekbk7JuautTKnAECmHtBYe-650-80.png.webp 650w, https:\/\/cdn.mos.cms.futurecdn.net\/ekbk7JuautTKnAECmHtBYe-970-80.png.webp 970w, https:\/\/cdn.mos.cms.futurecdn.net\/ekbk7JuautTKnAECmHtBYe-1024-80.png.webp 1024w, https:\/\/cdn.mos.cms.futurecdn.net\/ekbk7JuautTKnAECmHtBYe-1200-80.png.webp 1200w\" sizes=\"(min-width: 1000px) 970px, calc(100vw - 40px)\"\/><img decoding=\"async\" alt=\"Change Permissions on the Linux Command Line\" class=\"expandable\" srcset=\"https:\/\/cdn.mos.cms.futurecdn.net\/ekbk7JuautTKnAECmHtBYe-320-80.png 320w, https:\/\/cdn.mos.cms.futurecdn.net\/ekbk7JuautTKnAECmHtBYe-480-80.png 480w, https:\/\/cdn.mos.cms.futurecdn.net\/ekbk7JuautTKnAECmHtBYe-650-80.png 650w, https:\/\/cdn.mos.cms.futurecdn.net\/ekbk7JuautTKnAECmHtBYe-970-80.png 970w, https:\/\/cdn.mos.cms.futurecdn.net\/ekbk7JuautTKnAECmHtBYe-1024-80.png 1024w, https:\/\/cdn.mos.cms.futurecdn.net\/ekbk7JuautTKnAECmHtBYe-1200-80.png 1200w\" sizes=\"(min-width: 1000px) 970px, calc(100vw - 40px)\" loading=\"lazy\" src=\"https:\/\/cdn.mos.cms.futurecdn.net\/ekbk7JuautTKnAECmHtBYe.png\" data-pin-media=\"https:\/\/cdn.mos.cms.futurecdn.net\/ekbk7JuautTKnAECmHtBYe.png\"\/><\/picture><\/p>\n<\/div>\n<\/div><figcaption itemprop=\"caption description\" class=\"inline-layout\"><span class=\"credit\" itemprop=\"copyrightHolder\">(Image credit: Tom&#8217;s Hardware)<\/span><\/figcaption><\/figure>\n<p>To begin, let&#8217;s create a test file in a test directory and take a look at its default permissions. To see the permissions we will use <em>ls <\/em>with the <em>-l<\/em> argument added.<\/p>\n<p>1. <strong>Create a new directory called <\/strong><em><strong>test_directory<\/strong><\/em><\/p>\n<pre class=\"line-numbers language-bash\" language=\"bash\"><code>$ mkdir test_directory<\/code><\/pre>\n<p>2. <strong>Move into the newly created directory<\/strong>.<\/p>\n<div id=\"slice-container-newsletterForm-articleInbodyContent-NTnLGkTvyDQucYwkD9ouDa\" class=\"slice-container newsletter-inbodyContent-slice newsletterForm-articleInbodyContent-NTnLGkTvyDQucYwkD9ouDa slice-container-newsletterForm\">\n<div data-hydrate=\"true\" class=\"newsletter-form__wrapper newsletter-form__wrapper--inbodyContent\">\n<div class=\"newsletter-form__container\">\n<section class=\"newsletter-form__top-bar\"\/>\n<section class=\"newsletter-form__main-section\">\n<p class=\"newsletter-form__strapline\">Get Tom&#8217;s Hardware&#8217;s best news and in-depth reviews, straight to your inbox.<\/p>\n<\/section>\n<\/div>\n<\/div>\n<\/div>\n<pre class=\"line-numbers language-bash\" language=\"bash\"><code>$ cd test_directory<\/code><\/pre>\n<p>3. <strong>Create a new test file called <\/strong><em><strong>test1.txt<\/strong><\/em><strong>.<\/strong><\/p>\n<pre class=\"line-numbers language-bash\" language=\"bash\"><code>$ touch test1.txt<\/code><\/pre>\n<p>4. <strong>List the contents of the directory using <\/strong><em><strong>ls -l<\/strong><\/em><strong>.<\/strong><\/p>\n<pre class=\"line-numbers language-bash\" language=\"bash\"><code>$ ls -l<\/code><\/pre>\n<p>Using <em>ls -l<\/em> gives us a lot more information about the items returned on the list. We should see that<em> test1.txt<\/em> has been created. We are interested in the first 10 characters on the listing which for our test file read <em>&#8211; rw- rw- r&#8211;<\/em>.<\/p>\n<p>The first \u2013 indicates that the object on the list is a file. If we ran<em> ls -l<\/em> and a directory was listed this first character would be a<em> d<\/em>. The next 9 characters are arranged in 3 sets of 3.<\/p>\n<p>The first set of 3 refers to the owner, the second set of 3 refer to user groups and the final set of three refer to others. Each set of 3 characters can contain either \u2013 or r, w, and x. If you can see an r in the set then that set has read permissions granted. If you can see a w that set can write to a file and if you can see an x in the set then that set can execute the file as a script or program.<\/p>\n<p>We can see that our <em>test1.txt <\/em>currently has the owner and group member permissions set to read and write with others only allowed to read. No one has permission to execute the file.<\/p>\n<h2 id=\"how-to-change-linux-file-directory-permissions-quickly-3\">How to Change Linux File \/ Directory Permissions Quickly<\/h2>\n<figure class=\"van-image-figure  inline-layout\" data-bordeaux-image-check=\"\">\n<div class=\"image-full-width-wrapper\">\n<div class=\"image-widthsetter\" style=\"max-width:1572px;\">\n<p class=\"vanilla-image-block\" style=\"padding-top:67.81%;\"><picture><source type=\"image\/webp\" srcset=\"https:\/\/cdn.mos.cms.futurecdn.net\/FPvjdEzu6XTFPABMr9J9pe-320-80.png.webp 320w, https:\/\/cdn.mos.cms.futurecdn.net\/FPvjdEzu6XTFPABMr9J9pe-480-80.png.webp 480w, https:\/\/cdn.mos.cms.futurecdn.net\/FPvjdEzu6XTFPABMr9J9pe-650-80.png.webp 650w, https:\/\/cdn.mos.cms.futurecdn.net\/FPvjdEzu6XTFPABMr9J9pe-970-80.png.webp 970w, https:\/\/cdn.mos.cms.futurecdn.net\/FPvjdEzu6XTFPABMr9J9pe-1024-80.png.webp 1024w, https:\/\/cdn.mos.cms.futurecdn.net\/FPvjdEzu6XTFPABMr9J9pe-1200-80.png.webp 1200w\" sizes=\"(min-width: 1000px) 970px, calc(100vw - 40px)\"\/><img decoding=\"async\" alt=\"Change Permissions on the Linux Command Line\" class=\"expandable\" srcset=\"https:\/\/cdn.mos.cms.futurecdn.net\/FPvjdEzu6XTFPABMr9J9pe-320-80.png 320w, https:\/\/cdn.mos.cms.futurecdn.net\/FPvjdEzu6XTFPABMr9J9pe-480-80.png 480w, https:\/\/cdn.mos.cms.futurecdn.net\/FPvjdEzu6XTFPABMr9J9pe-650-80.png 650w, https:\/\/cdn.mos.cms.futurecdn.net\/FPvjdEzu6XTFPABMr9J9pe-970-80.png 970w, https:\/\/cdn.mos.cms.futurecdn.net\/FPvjdEzu6XTFPABMr9J9pe-1024-80.png 1024w, https:\/\/cdn.mos.cms.futurecdn.net\/FPvjdEzu6XTFPABMr9J9pe-1200-80.png 1200w\" sizes=\"(min-width: 1000px) 970px, calc(100vw - 40px)\" loading=\"lazy\" src=\"https:\/\/cdn.mos.cms.futurecdn.net\/FPvjdEzu6XTFPABMr9J9pe.png\" data-pin-media=\"https:\/\/cdn.mos.cms.futurecdn.net\/FPvjdEzu6XTFPABMr9J9pe.png\"\/><\/picture><\/p>\n<\/div>\n<\/div><figcaption itemprop=\"caption description\" class=\"inline-layout\"><span class=\"credit\" itemprop=\"copyrightHolder\">(Image credit: Tom&#8217;s Hardware)<\/span><\/figcaption><\/figure>\n<p>We can use the <em>chmod <\/em>command to toggle the read, write and execute permissions on and off for the owner, group and others. Let\u2019s begin with changing single permissions for the owner and group.<\/p>\n<p>1. In the <em>test_directory,<\/em> <strong>list the current permissions for <\/strong><em><strong>test1.txt<\/strong><\/em><strong>.<\/strong><\/p>\n<pre class=\"line-numbers language-bash\" language=\"bash\"><code>$ ls -l<\/code><\/pre>\n<p>These should be unchanged from when we created <em>test1.txt <\/em>and should read <em>-rw-rw-r&#8211; .<\/em><\/p>\n<p>2. <strong>Change the permission of the owner to read only<\/strong>.<\/p>\n<pre class=\"line-numbers language-bash\" language=\"bash\"><code>$ chmod u-w test1.txt<\/code><\/pre>\n<p>3. <strong>List the directory contents<\/strong> to view the new permission settings. We should now see that the permissions for <em>test1.txt <\/em>read -r&#8211;rw-r&#8211; indicating that, for the owner, the file is now read only.<\/p>\n<pre class=\"line-numbers language-bash\" language=\"bash\"><code>$ ls -l<\/code><\/pre>\n<p>4. <strong>Change  permission of groups to read only. <\/strong>Similar to changing permissions for the owner we can change permission settings for the groups. To revoke write permissions we can use the argument <em>g-w<\/em>.<\/p>\n<pre class=\"line-numbers language-bash\" language=\"bash\"><code>$ chmod g-w test1.txt<\/code><\/pre>\n<p>5. <strong>List the directory contents <\/strong>to view the new permission settings<strong>.<\/strong><\/p>\n<pre class=\"line-numbers language-bash\" language=\"bash\"><code>$ ls -l<\/code><\/pre>\n<p>We should now see that the permissions for <em>test1.txt <\/em>read -r&#8211;r&#8211;r&#8211; indicating that, for the groups, the file is now read only.<\/p>\n<p>6. <strong>Enable write permissions for the owner. <\/strong>Instead of using <em>u-w <\/em>to remove write permissions we can intuitively use <em>u+w <\/em>to grant write permissions for the owner.<\/p>\n<pre class=\"line-numbers language-bash\" language=\"bash\"><code>$ chmod u+w test1.txt<\/code><\/pre>\n<p>7. <strong>List the directory contents <\/strong>to view the new permission settings. We should now see that the permissions for <em>test1.txt <\/em>read -rw-r&#8211;r&#8211; indicating that, for the owner, write permissions have been granted.<\/p>\n<pre class=\"line-numbers language-bash\" language=\"bash\"><code>$ ls -l<\/code><\/pre>\n<h2 id=\"how-to-apply-multiple-file-directory-permission-changes-in-linux-3\">How to Apply Multiple File \/ Directory Permission Changes in Linux<\/h2>\n<figure class=\"van-image-figure  inline-layout\" data-bordeaux-image-check=\"\">\n<div class=\"image-full-width-wrapper\">\n<div class=\"image-widthsetter\" style=\"max-width:1572px;\">\n<p class=\"vanilla-image-block\" style=\"padding-top:67.81%;\"><picture><source type=\"image\/webp\" srcset=\"https:\/\/cdn.mos.cms.futurecdn.net\/BY3RJGKxbbHd9v4nvuNmge-320-80.png.webp 320w, https:\/\/cdn.mos.cms.futurecdn.net\/BY3RJGKxbbHd9v4nvuNmge-480-80.png.webp 480w, https:\/\/cdn.mos.cms.futurecdn.net\/BY3RJGKxbbHd9v4nvuNmge-650-80.png.webp 650w, https:\/\/cdn.mos.cms.futurecdn.net\/BY3RJGKxbbHd9v4nvuNmge-970-80.png.webp 970w, https:\/\/cdn.mos.cms.futurecdn.net\/BY3RJGKxbbHd9v4nvuNmge-1024-80.png.webp 1024w, https:\/\/cdn.mos.cms.futurecdn.net\/BY3RJGKxbbHd9v4nvuNmge-1200-80.png.webp 1200w\" sizes=\"(min-width: 1000px) 970px, calc(100vw - 40px)\"\/><img decoding=\"async\" alt=\"Change Permissions on the Linux Command Line\" class=\"expandable\" srcset=\"https:\/\/cdn.mos.cms.futurecdn.net\/BY3RJGKxbbHd9v4nvuNmge-320-80.png 320w, https:\/\/cdn.mos.cms.futurecdn.net\/BY3RJGKxbbHd9v4nvuNmge-480-80.png 480w, https:\/\/cdn.mos.cms.futurecdn.net\/BY3RJGKxbbHd9v4nvuNmge-650-80.png 650w, https:\/\/cdn.mos.cms.futurecdn.net\/BY3RJGKxbbHd9v4nvuNmge-970-80.png 970w, https:\/\/cdn.mos.cms.futurecdn.net\/BY3RJGKxbbHd9v4nvuNmge-1024-80.png 1024w, https:\/\/cdn.mos.cms.futurecdn.net\/BY3RJGKxbbHd9v4nvuNmge-1200-80.png 1200w\" sizes=\"(min-width: 1000px) 970px, calc(100vw - 40px)\" loading=\"lazy\" src=\"https:\/\/cdn.mos.cms.futurecdn.net\/BY3RJGKxbbHd9v4nvuNmge.png\" data-pin-media=\"https:\/\/cdn.mos.cms.futurecdn.net\/BY3RJGKxbbHd9v4nvuNmge.png\"\/><\/picture><\/p>\n<\/div>\n<\/div><figcaption itemprop=\"caption description\" class=\"inline-layout\"><span class=\"credit\" itemprop=\"copyrightHolder\">(Image credit: Tom&#8217;s Hardware)<\/span><\/figcaption><\/figure>\n<p>We can also combine the arguments we used in the previous section to make multiple changes to Linux file permissions in a single command. In this section it\u2019s important not to add any extra spaces in the <em>chmod <\/em>arguments as this will cause the command to fail.<\/p>\n<p>In the first section we used <em>u <\/em>and <em>g <\/em>for<em> owner <\/em>and <em>group <\/em>and in this section we will additionally use <em>o <\/em>to target permission changes for <em>others. <\/em>Likewise, we used <em>r <\/em>and <em>w <\/em>for <em>read <\/em>and <em>write <\/em>and in this section we will add <em>x <\/em>to make changes to the executable permissions.<\/p>\n<p>1. <strong>List the directory contents<\/strong> to view the new permission settings. We should see that the permissions for <em>test1.txt<\/em> are -rw-r&#8211;r&#8211; .<\/p>\n<pre class=\"line-numbers language-bash\" language=\"bash\"><code>$ ls -l<\/code><\/pre>\n<p>2. <strong>Change the permissions so that additionally the owner can execute and the group can additionally write and execute. <\/strong>Notice that there are no spaces after the comma and also notice that you can combine <em>r,w,x <\/em>in a single argument.<\/p>\n<pre class=\"line-numbers language-bash\" language=\"bash\"><code>$ chmod u+x,g+wx test1.txt<\/code><\/pre>\n<p>3. <strong>List the directory contents to view the new permission settings.<\/strong> We should see that the permissions for <em>test1.txt<\/em> are -rwxrwxr&#8211; . This means that the <em>owner<\/em> and <em>group <\/em>can read, write and execute the file whilst others can only read.<\/p>\n<pre class=\"line-numbers language-bash\" language=\"bash\"><code>$ ls -l<\/code><\/pre>\n<h2 id=\"how-to-change-file-directory-permissions-recursively-in-linux-3\">How to Change File \/ Directory Permissions Recursively in Linux<\/h2>\n<figure class=\"van-image-figure  inline-layout\" data-bordeaux-image-check=\"\">\n<div class=\"image-full-width-wrapper\">\n<div class=\"image-widthsetter\" style=\"max-width:1572px;\">\n<p class=\"vanilla-image-block\" style=\"padding-top:95.29%;\"><picture><source type=\"image\/webp\" srcset=\"https:\/\/cdn.mos.cms.futurecdn.net\/EKeveiv5KZq8jTAPmPUo3f-320-80.png.webp 320w, https:\/\/cdn.mos.cms.futurecdn.net\/EKeveiv5KZq8jTAPmPUo3f-480-80.png.webp 480w, https:\/\/cdn.mos.cms.futurecdn.net\/EKeveiv5KZq8jTAPmPUo3f-650-80.png.webp 650w, https:\/\/cdn.mos.cms.futurecdn.net\/EKeveiv5KZq8jTAPmPUo3f-970-80.png.webp 970w, https:\/\/cdn.mos.cms.futurecdn.net\/EKeveiv5KZq8jTAPmPUo3f-1024-80.png.webp 1024w, https:\/\/cdn.mos.cms.futurecdn.net\/EKeveiv5KZq8jTAPmPUo3f-1200-80.png.webp 1200w\" sizes=\"(min-width: 1000px) 970px, calc(100vw - 40px)\"\/><img decoding=\"async\" alt=\"Change Permissions on the Linux Command Line\" class=\"expandable\" srcset=\"https:\/\/cdn.mos.cms.futurecdn.net\/EKeveiv5KZq8jTAPmPUo3f-320-80.png 320w, https:\/\/cdn.mos.cms.futurecdn.net\/EKeveiv5KZq8jTAPmPUo3f-480-80.png 480w, https:\/\/cdn.mos.cms.futurecdn.net\/EKeveiv5KZq8jTAPmPUo3f-650-80.png 650w, https:\/\/cdn.mos.cms.futurecdn.net\/EKeveiv5KZq8jTAPmPUo3f-970-80.png 970w, https:\/\/cdn.mos.cms.futurecdn.net\/EKeveiv5KZq8jTAPmPUo3f-1024-80.png 1024w, https:\/\/cdn.mos.cms.futurecdn.net\/EKeveiv5KZq8jTAPmPUo3f-1200-80.png 1200w\" sizes=\"(min-width: 1000px) 970px, calc(100vw - 40px)\" loading=\"lazy\" src=\"https:\/\/cdn.mos.cms.futurecdn.net\/EKeveiv5KZq8jTAPmPUo3f.png\" data-pin-media=\"https:\/\/cdn.mos.cms.futurecdn.net\/EKeveiv5KZq8jTAPmPUo3f.png\"\/><\/picture><\/p>\n<\/div>\n<\/div><figcaption itemprop=\"caption description\" class=\"inline-layout\"><span class=\"credit\" itemprop=\"copyrightHolder\">(Image credit: Tom&#8217;s Hardware)<\/span><\/figcaption><\/figure>\n<p>The <em>chmod <\/em>command can be used to create changes recursively to a directory meaning that changes are also applied to the files contained within the directory. Let\u2019s use what we have learnt so far and additionally use the recursive <em>-R <\/em>argument to see how this works.<\/p>\n<p>1. <strong>Move to your home directory and list the contents.<\/strong><\/p>\n<pre class=\"line-numbers language-bash\" language=\"bash\"><code>$ cd\n$ ls -l<\/code><\/pre>\n<p>We should see test_directory listed from the previous parts of this how-to. The permissions for test_directory should read drwxrwxr-x.<\/p>\n<p>2. <strong>Change the owner and group permissions of both the directory and its contents. <\/strong>Running this command will revoke owner and group write permissions for both <em>test_directory <\/em>and the file, <em>test1.txt<\/em> it contains.<\/p>\n<pre class=\"line-numbers language-bash\" language=\"bash\"><code>$ chmod -R u-w,g-w test_directory<\/code><\/pre>\n<p>3. <strong>List the home directory contents<\/strong> to check the permissions for <em>test_directory.<\/em><\/p>\n<pre class=\"line-numbers language-bash\" language=\"bash\"><code>$ ls -l\n<\/code><\/pre>\n<p>We should see that the owner and group permissions allow for reading and execution but now do not allow writing to the directory.<\/p>\n<p>4. <strong>Move into <\/strong><em><strong>test_directory<\/strong><\/em> to check permissions for<em> test1.txt.<\/em><\/p>\n<pre class=\"line-numbers language-bash\" language=\"bash\"><code>$ cd test_directory\n$ ls -l<\/code><\/pre>\n<p>We should see that the owner and group permissions for<em>test1.txt <\/em>have been changed to match the recursive changes to the host directory, removing write permissions.<\/p>\n<h2 id=\"how-to-view-your-linux-group-3\">How to View Your Linux Group<\/h2>\n<p>When we talk of users, groups and others what we mean is that our user typically belongs to a group of users. A user and group can have the same, or very different permissions. For example a team member may need more permissions to perform a certain task. The permissions that we give a user and a group will be different to what we give other users, users who are not in the group.<\/p>\n<p>We can see the groups that our user is part of via the <em>groups<\/em> command.<\/p>\n<p>1. <strong>Open a terminal and type in <\/strong><em><strong>groups<\/strong><\/em><strong>. <\/strong>This will list all of the groups available on our installation.<\/p>\n<pre class=\"line-numbers language-bash\" language=\"bash\"><code>groups<\/code><\/pre>\n<p>2. <strong>Open a terminal and type in <\/strong><em><strong>groups<\/strong><\/em><strong> followed by the user\u2019s name. <\/strong>For example here we check which groups \u201cTom\u201d belongs to and find that he belongs to the groups tom and sudo.<\/p>\n<pre class=\"line-numbers language-bash\" language=\"bash\"><code>groups tom\n<\/code><\/pre>\n<p>The output of this command looks like this.<\/p>\n<pre class=\"line-numbers language-bash\" language=\"bash\"><code>tom : tom sudo<\/code><\/pre>\n<p>Others are not a group. Rather \u201cothers\u201d refers to anyone who is not the owner, or in a group which has access to a file or directory. Typically others will only have read access to any files of directories, but this can be changed and we shall explore this later.<\/p>\n<h2 id=\"how-to-change-linux-file-permissions-with-numeric-codes-3\">How to Change Linux File Permissions With Numeric Codes<\/h2>\n<p>Though the use of r,w or x is easier to remember for Linux file permissions, many people use a series of numeric codes with chmod instead. You feed the chmod command a three-digit number and each digit applies to a different group in this order: user, group, others. So, for example, <em>chmod 777<\/em> gives all three types full read, write and execute permissions while <em>chmod 740<\/em> gives the user full permissions, the group read permissions and others no permissions at all.<\/p>\n<p>The table below shows what each number means.<\/p>\n<div id=\"slice-container-table-NTnLGkTvyDQucYwkD9ouDa-hTkC3HKKphxjCXsgMzQXFbEzQPc619wg\" class=\"slice-container table-wrapper table-NTnLGkTvyDQucYwkD9ouDa-hTkC3HKKphxjCXsgMzQXFbEzQPc619wg slice-container-table\">\n<div class=\"table__instruction\">Swipe to scroll horizontally<svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" viewbox=\"0 0 23 30\" fill=\"none\"><path d=\"M21.554 15.726a2.878 2.878 0 0 0-1.705-.374 2.881 2.881 0 0 0-1.388-3.068 2.877 2.877 0 0 0-1.992-.333 2.884 2.884 0 0 0-.1-.766 2.865 2.865 0 0 0-1.346-1.75c-.47-.27-.996-.4-1.527-.385l2.742-4.73a2.87 2.87 0 0 0 .323-.83h2.612V2.084h-2.661A2.861 2.861 0 0 0 15.18.385a2.903 2.903 0 0 0-3.952 1.055l-.373.644H2.983l1.003-1L2.99.09 1.28 1.793l-.999.995L2.99 5.484l.998-.994-1.003-.999h7.054L6.505 9.586c-.34.066-.905.186-1.523.366-1.405.41-2.321.895-2.8 1.483-.742.911-1.159 2.513-1.277 4.898l-.001.01c-.067 1.816.946 6.943.99 7.16a.688.688 0 0 0 1.35-.266c-.01-.051-1.023-5.177-.963-6.84.127-2.556.598-3.64.97-4.098.133-.163.602-.587 2.104-1.027l.206-.058-1.425 2.458a.685.685 0 0 0 .252.937c.33.19.75.077.94-.251L12.42 2.126a1.52 1.52 0 0 1 2.07-.552c.35.2.6.527.705.916.105.39.051.797-.15 1.145l-4.767 8.222a.685.685 0 0 0 .252.937c.33.19.75.077.94-.25l.794-1.368c.201-.348.529-.597.92-.702a1.508 1.508 0 0 1 1.854 1.066c.105.39.052.796-.15 1.144l-.377.652-.002.002-.898 1.55a.685.685 0 0 0 .252.938c.329.189.75.077.94-.251l.9-1.551c.201-.348.528-.597.92-.702a1.512 1.512 0 0 1 1.703 2.21l-1.223 2.11a.685.685 0 0 0 .252.938c.33.189.75.076.941-.252l.5-.862c.202-.348.529-.597.92-.702.392-.104.8-.051 1.15.15.723.416.972 1.34.554 2.06l-3.525 6.08c-.517.892-1.57 1.795-3.044 2.611-1.156.64-2.163.998-2.173 1.002a.685.685 0 0 0 .23 1.333.688.688 0 0 0 .229-.04c.18-.062 4.419-1.575 5.952-4.22l3.524-6.08a2.878 2.878 0 0 0-1.059-3.934Z\" fill=\"#333\"\/><\/svg><\/div>\n<div class=\"table__container\">\n<table tabindex=\"0\" class=\"table__wrapper table__wrapper--inbodyContent table__wrapper--sticky table__wrapper--divider\">\n<thead class=\"table__head\">\n<tr class=\"table__head__row\">\n<th class=\"table__head__heading table__head__heading--left\" colspan=\"1\">\n<p>Number<\/p>\n<\/th>\n<th class=\"table__head__heading table__head__heading--left\" colspan=\"1\">\n<p>Permissions<\/p>\n<\/th>\n<\/tr>\n<\/thead>\n<tbody class=\"table__body\">\n<tr class=\"table__body__row\">\n<td class=\"table_body__data\" colspan=\"1\" style=\"text-align:left\">\n<p>0<\/p>\n<\/td>\n<td class=\"table_body__data\" colspan=\"1\" style=\"text-align:left\">\n<p>None<\/p>\n<\/td>\n<\/tr>\n<tr class=\"table__body__row\">\n<td class=\"table_body__data\" colspan=\"1\" style=\"text-align:left\">\n<p>1<\/p>\n<\/td>\n<td class=\"table_body__data\" colspan=\"1\" style=\"text-align:left\">\n<p>Execute<\/p>\n<\/td>\n<\/tr>\n<tr class=\"table__body__row\">\n<td class=\"table_body__data\" colspan=\"1\" style=\"text-align:left\">\n<p>2<\/p>\n<\/td>\n<td class=\"table_body__data\" colspan=\"1\" style=\"text-align:left\">\n<p>Write\u00a0<\/p>\n<\/td>\n<\/tr>\n<tr class=\"table__body__row\">\n<td class=\"table_body__data\" colspan=\"1\" style=\"text-align:left\">\n<p>3<\/p>\n<\/td>\n<td class=\"table_body__data\" colspan=\"1\" style=\"text-align:left\">\n<p>Execute and Write\u00a0<\/p>\n<\/td>\n<\/tr>\n<tr class=\"table__body__row\">\n<td class=\"table_body__data\" colspan=\"1\" style=\"text-align:left\">\n<p>4<\/p>\n<\/td>\n<td class=\"table_body__data\" colspan=\"1\" style=\"text-align:left\">\n<p>Read<\/p>\n<\/td>\n<\/tr>\n<tr class=\"table__body__row\">\n<td class=\"table_body__data\" colspan=\"1\" style=\"text-align:left\">\n<p>5<\/p>\n<\/td>\n<td class=\"table_body__data\" colspan=\"1\" style=\"text-align:left\">\n<p>Read and Execute<\/p>\n<\/td>\n<\/tr>\n<tr class=\"table__body__row\">\n<td class=\"table_body__data\" colspan=\"1\" style=\"text-align:left\">\n<p>6<\/p>\n<\/td>\n<td class=\"table_body__data\" colspan=\"1\" style=\"text-align:left\">\n<p>Read and Write<\/p>\n<\/td>\n<\/tr>\n<tr class=\"table__body__row\">\n<td class=\"table_body__data\" colspan=\"1\" style=\"text-align:left\">\n<p>7<\/p>\n<\/td>\n<td class=\"table_body__data\" colspan=\"1\" style=\"text-align:left\">\n<p>All: Read, Write and Execute<\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<p>With these basic usages of the <em>chmod <\/em>command you get a lot of control over file and directory permissions. There are lots of different arguments to add to <em>chmod <\/em>that allow you to work with different approaches.<\/p>\n<p>For example it\u2019s worth researching the use of <em>= <\/em>instead of + and \u2013 as, rather than toggling permissions on and off, you can define permissions directly for some or all users. As you research and learn about <em>chmod <\/em>it\u2019s worth remembering to practice on test files and directories as it can be frustrating if you accidentally remove all permissions on a file you depend on.<\/p>\n<\/div>\n<p>[\/gpt3]<br \/>\n<br \/><a href=\"https:\/\/www.tomshardware.com\/software\/linux\/how-to-change-file-or-directory-permissions-via-the-linux-terminal\">Source link <\/a><\/p>","protected":false},"excerpt":{"rendered":"<p>If you\u2019ve ever tried to run a script from the command line in Linux and gotten an error message saying that it\u2019s not executable or attempted to enter a directory only to be blocked by the system, you probably don\u2019t have permissions to do those things. Fortunately, if you have the proper rights or the [&hellip;]<\/p>","protected":false},"author":1,"featured_media":5169,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_seopress_robots_primary_cat":"","_seopress_titles_title":"","_seopress_titles_desc":"","_seopress_robots_index":"","footnotes":""},"categories":[1],"tags":[],"class_list":{"0":"post-5168","1":"post","2":"type-post","3":"status-publish","4":"format-standard","5":"has-post-thumbnail","7":"category-blog"},"_links":{"self":[{"href":"https:\/\/cicserver.com\/de\/wp-json\/wp\/v2\/posts\/5168","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/cicserver.com\/de\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/cicserver.com\/de\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/cicserver.com\/de\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/cicserver.com\/de\/wp-json\/wp\/v2\/comments?post=5168"}],"version-history":[{"count":0,"href":"https:\/\/cicserver.com\/de\/wp-json\/wp\/v2\/posts\/5168\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/cicserver.com\/de\/wp-json\/wp\/v2\/media\/5169"}],"wp:attachment":[{"href":"https:\/\/cicserver.com\/de\/wp-json\/wp\/v2\/media?parent=5168"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/cicserver.com\/de\/wp-json\/wp\/v2\/categories?post=5168"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/cicserver.com\/de\/wp-json\/wp\/v2\/tags?post=5168"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}