{"id":665,"date":"2019-11-20T09:31:33","date_gmt":"2019-11-20T09:31:33","guid":{"rendered":"http:\/\/blog.hostinger.io\/hostinger-tutorials\/uncategorized\/vpshow-to-change-permissions-and-owners-via-command-line\/"},"modified":"2026-09-15T10:27:59","modified_gmt":"2026-09-15T10:27:59","slug":"how-to-change-linux-permissions-and-owners","status":"publish","type":"post","link":"\/tutorials\/how-to-change-linux-permissions-and-owners\/","title":{"rendered":"How to change permissions and ownership in Linux"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">Properly managing Linux file permissions and ownership is essential for safety, especially when multiple administrators manage one server. Moreover, using the correct settings ensures your server can run properly.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">This article will explain how to change permissions and ownership in Linux. Before that, you will learn about the structure of item permissions and ownership on Linux operating systems.<\/p>\n\n\n\n\n\n\n<h2 class=\"wp-block-heading h-t-title-2\" id=\"h-overview-of-changing-linux-permissions\">Overview of changing Linux permissions<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">The commands for changing file and directory permissions are the same. Here are some of the most popular ones:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>chmod +rwx item<\/strong> \u2013 adds read, write, and execute permissions.<\/li>\n\n\n\n<li><strong>chmod -rwx item<\/strong> \u2013 removes all permissions from an item.<\/li>\n\n\n\n<li><strong>chmod +r item <\/strong>\u2013 grants the read permission over an item.&nbsp;<\/li>\n\n\n\n<li><strong>chmod -x item<\/strong> \u2013 prevents all users from executing the item.&nbsp;<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">You can further fine-tune the permission settings for different users. We\u2019ll explain it more in the following sections.<\/p>\n\n\n<div class=\"announcement-block announcement-block--important\">\n            <span class=\"announcement-block__heading\">\n                <svg aria-hidden=\"true\" width=\"24\" height=\"24\" viewBox=\"0 0 24 24\" fill=\"none\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n                    <path fill-rule=\"evenodd\" clip-rule=\"evenodd\"\n                          d=\"M12 22.5C17.799 22.5 22.5 17.799 22.5 12C22.5 6.20101 17.799 1.5 12 1.5C6.20101 1.5 1.5 6.20101 1.5 12C1.5 17.799 6.20101 22.5 12 22.5ZM13.637 7.65198C13.637 6.74791 12.9041 6.01501 12 6.01501C11.0959 6.01501 10.363 6.74791 10.363 7.65198C10.5335 9.53749 10.875 13.383 10.875 13.383C10.875 14.0043 11.3787 14.508 12 14.508C12.6213 14.508 13.125 14.0043 13.125 13.383V13.38L13.637 7.65198ZM11.9927 15.714C11.3714 15.714 10.8677 16.2177 10.8677 16.839C10.8677 17.4603 11.3714 17.964 11.9927 17.964H12.0073C12.6286 17.964 13.1323 17.4603 13.1323 16.839C13.1323 16.2177 12.6286 15.714 12.0073 15.714H11.9927Z\"\n                          fill=\"#FEA419\"\/>\n                <\/svg>\n                Important\n            <\/span>\n            <p class=\"announcement-block__content\">\n                <strong>Important!<\/strong><br \/>\nIf you encounter an error message about privilege when modifying permissions or ownership, start your command with <strong>sudo<\/strong>.\n            <\/p><\/div>\n\n\n\n<h2 class=\"wp-block-heading h-t-title-2\" id=\"h-understanding-the-linux-permissions-model\">Understanding the Linux permissions model<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Users and groups<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Linux operating systems have three classes to which you can grant permissions and ownership:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>owner <\/strong>\u2013 a user that possesses the file or folder.&nbsp;<\/li>\n\n\n\n<li><strong>group <\/strong>\u2013 multiple users that belong to the same category.&nbsp;<\/li>\n\n\n\n<li><strong>others<\/strong> \u2013 all users who are neither the owner nor the group member.&nbsp;<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Permission types<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">In Linux, files and folders have three types of permissions, each with an initial. Here\u2019s their explanation:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>read<\/strong> (<strong>r<\/strong>) \u2013 allows users to view the content of a file or directory.<\/li>\n\n\n\n<li><strong>write<\/strong> (<strong>w<\/strong>) \u2013 lets users edit a file\u2019s content. For directories, they can create, delete, and move files within the folder.<\/li>\n\n\n\n<li><strong>execute<\/strong> (<strong>x<\/strong>) \u2013 enables users to run a file. Executable permissions over a folder mean users can open it and gain access to all its data.<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading h-t-title-2\" id=\"h-viewing-current-permissions\">Viewing current permissions<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Since managing permissions requires commands, open your system\u2019s command-line interface. Use Terminal for a local computer or <a data-click-id=\"hgr-post-content-link-connect-via-ssh\" href=\"\/tutorials\/how-to-use-putty-ssh\/\">connect via SSH<\/a> if you use a remote system like a virtual private server (VPS).<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Alternatively, if you use the <a data-click-id=\"hgr-post-content-link-hostinger-vps-platform\" href=\"\/vps-hosting\">Hostinger VPS platform<\/a>, access your system\u2019s CLI with one click using <strong>Browser terminal<\/strong>. Simply open your VPS management menu on Hostinger dashboard and hit the button.&nbsp;<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><a data-click-id=\"hgr-post-content-link-vps-hosting\" aria-label=\"Vps hosting\" class=\"hgr-tutorials-cta hgr-tutorials-cta-vps-hosting\" href=\"\/vps-hosting\" target=\"_blank\" rel=\"noopener\"><img decoding=\"async\" width=\"1024\" height=\"300\" src=\"https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2023\/02\/VPS-hosting-banner.png\/w=1024,h=1024,fit=scale-down\" alt=\"\" class=\"wp-image-77934\" srcset=\"https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2023\/02\/VPS-hosting-banner.png\/w=1024,fit=scale-down 1024w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2023\/02\/VPS-hosting-banner.png\/w=300,fit=scale-down 300w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2023\/02\/VPS-hosting-banner.png\/w=150,fit=scale-down 150w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2023\/02\/VPS-hosting-banner.png\/w=768,fit=scale-down 768w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/a><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">To view files and folders permission in your current working directory, run the following command:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">ls -l<\/pre>\n\n\n<div class=\"wp-block-image\">\n<figure data-wp-context=\"{&quot;imageId&quot;:&quot;6b15231c1d21e&quot;}\" data-wp-interactive=\"core\/image\" data-wp-key=\"6b15231c1d21e\" class=\"aligncenter size-large wp-lightbox-container\"><img decoding=\"async\" width=\"1030\" height=\"140\" data-wp-class--hide=\"state.isContentHidden\" data-wp-class--show=\"state.isContentVisible\" data-wp-init=\"callbacks.setButtonStyles\" data-wp-on--click=\"actions.showLightbox\" data-wp-on--load=\"callbacks.setButtonStyles\" data-wp-on--pointerdown=\"actions.preloadImage\" data-wp-on--pointerenter=\"actions.preloadImageWithDelay\" data-wp-on--pointerleave=\"actions.cancelPreload\" data-wp-on-window--resize=\"callbacks.setButtonStyles\" src=\"https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2019\/11\/list-of-items-and-their-permissions-in-linux.png\/w=1024,h=1024,fit=scale-down\" alt=\"List of items and their permissions in Linux\n\" class=\"wp-image-120013\" srcset=\"https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2019\/11\/list-of-items-and-their-permissions-in-linux.png\/w=1030,fit=scale-down 1030w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2019\/11\/list-of-items-and-their-permissions-in-linux.png\/w=300,fit=scale-down 300w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2019\/11\/list-of-items-and-their-permissions-in-linux.png\/w=1024,fit=scale-down 1024w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2019\/11\/list-of-items-and-their-permissions-in-linux.png\/w=150,fit=scale-down 150w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2019\/11\/list-of-items-and-their-permissions-in-linux.png\/w=768,fit=scale-down 768w\" sizes=\"(max-width: 1030px) 100vw, 1030px\" \/><button\n\t\t\tclass=\"lightbox-trigger\"\n\t\t\ttype=\"button\"\n\t\t\taria-haspopup=\"dialog\"\n\t\t\tdata-wp-bind--aria-label=\"state.thisImage.triggerButtonAriaLabel\"\n\t\t\tdata-wp-init=\"callbacks.initTriggerButton\"\n\t\t\tdata-wp-on--click=\"actions.showLightbox\"\n\t\t\tdata-wp-style--right=\"state.thisImage.buttonRight\"\n\t\t\tdata-wp-style--top=\"state.thisImage.buttonTop\"\n\t\t>\n\t\t\t<svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"12\" height=\"12\" fill=\"none\" viewBox=\"0 0 12 12\">\n\t\t\t\t<path fill=\"#fff\" d=\"M2 0a2 2 0 0 0-2 2v2h1.5V2a.5.5 0 0 1 .5-.5h2V0H2Zm2 10.5H2a.5.5 0 0 1-.5-.5V8H0v2a2 2 0 0 0 2 2h2v-1.5ZM8 12v-1.5h2a.5.5 0 0 0 .5-.5V8H12v2a2 2 0 0 1-2 2H8Zm2-12a2 2 0 0 1 2 2v2h-1.5V2a.5.5 0 0 0-.5-.5H8V0h2Z\" \/>\n\t\t\t<\/svg>\n\t\t<\/button><\/figure>\n<\/div>\n\n\n<p class=\"wp-block-paragraph\">If you want to check only a specific item, enter this command<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">ls -l itemname<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">You should see the output looks similar to the following:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">drwxrwxrwx 2 user1 admins 4096 Sep 12 04:33 config<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">This output contains various information. However, since we want to check the permissions and ownership, let\u2019s focus on <strong>user1<\/strong>, <strong>admins<\/strong>, <strong>config<\/strong>, and <strong>drwxrw-r&#8211;<\/strong>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The <strong>user1 <\/strong>placeholder specifies the item\u2019s owner, while <strong>admins<\/strong> is the Linux group the user belongs to. The item name is located at the end, which is <strong>config<\/strong>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The <strong>drwxrw-r&#8211; <\/strong>string<strong> <\/strong>tells you about the item\u2019s permission settings. Let\u2019s break it down:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>d<\/strong> \u2013 the first character of the string indicates the type of the item, which can be a directory (<strong>d<\/strong>), a regular file (<strong>&#8211;<\/strong>), or a <a data-click-id=\"hgr-post-content-link-symbolic-link\" href=\"\/tutorials\/how-to-create-symbolic-links-in-linux\/\">symbolic link<\/a> (<strong>l<\/strong>).<\/li>\n\n\n\n<li><strong>rwx<\/strong> \u2013 the second part specifies the owner&#8217;s permissions. Since we have <strong>rwx<\/strong>, <strong>user1<\/strong> can read, write, and execute the directory.<\/li>\n\n\n\n<li><strong>rw-<\/strong> \u2013 the third part determines the group permissions over the item. A hyphen (<strong>&#8211;<\/strong>) means missing permission, so the <strong>admins <\/strong>group members can only read and write the directory.&nbsp;<\/li>\n\n\n\n<li><strong>r&#8211; <\/strong>\u2013 the fourth part defines other users\u2019 permissions. Since we only have an <strong>r<\/strong> and two hyphens, others can only read the directory.&nbsp;<\/li>\n<\/ul>\n\n\n<div class=\"announcement-block announcement-block--important\">\n            <span class=\"announcement-block__heading\">\n                <svg aria-hidden=\"true\" width=\"24\" height=\"24\" viewBox=\"0 0 24 24\" fill=\"none\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n                    <path fill-rule=\"evenodd\" clip-rule=\"evenodd\"\n                          d=\"M12 22.5C17.799 22.5 22.5 17.799 22.5 12C22.5 6.20101 17.799 1.5 12 1.5C6.20101 1.5 1.5 6.20101 1.5 12C1.5 17.799 6.20101 22.5 12 22.5ZM13.637 7.65198C13.637 6.74791 12.9041 6.01501 12 6.01501C11.0959 6.01501 10.363 6.74791 10.363 7.65198C10.5335 9.53749 10.875 13.383 10.875 13.383C10.875 14.0043 11.3787 14.508 12 14.508C12.6213 14.508 13.125 14.0043 13.125 13.383V13.38L13.637 7.65198ZM11.9927 15.714C11.3714 15.714 10.8677 16.2177 10.8677 16.839C10.8677 17.4603 11.3714 17.964 11.9927 17.964H12.0073C12.6286 17.964 13.1323 17.4603 13.1323 16.839C13.1323 16.2177 12.6286 15.714 12.0073 15.714H11.9927Z\"\n                          fill=\"#FEA419\"\/>\n                <\/svg>\n                Important\n            <\/span>\n            <p class=\"announcement-block__content\">\n                <strong>Important<\/strong><br \/>\nThe permission naming structure and order will always remain the same.\n            <\/p><\/div>\n\n\n\n<h2 class=\"wp-block-heading h-t-title-2\" id=\"h-changing-permissions-with-chmod\">Changing permissions with chmod<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">To change item permissions, use the <strong>chmod<\/strong> <a data-click-id=\"hgr-post-content-link-linux-command\" href=\"\/tutorials\/linux-commands\/\">Linux command<\/a>. The syntax looks like the following:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">chmod [option] [mode] [file_folder_name]<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Option <\/strong>is an additional flag that modifies your chmod command behavior. You can check the complete list on the <a data-click-id=\"hgr-post-content-link-chmod-manual-page\" href=\"https:\/\/linux.die.net\/man\/1\/chmod\" target=\"_blank\" rel=\"noopener\">chmod manual page<\/a>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Mode <\/strong>is the new permissions for the file or folder, which you can write in<strong> symbolic<\/strong> or <strong>numeric <\/strong>notation. Both work the same way but have particular benefits, which we will explain in the following sections.<\/p>\n\n\n\n<h3 class=\"wp-block-heading h-t-title-3\" id=\"h-symbolic-mode\">Symbolic mode<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">The symbolic method in chmod uses a single character representing the user class, permissions, and operations. Here\u2019s the list:<\/p>\n\n\n\n<figure tabindex=\"0\" class=\"wp-block-table\"><table class=\"has-fixed-layout\"><tbody><tr><td><strong>Symbol<\/strong><\/td><td><strong>Definition<\/strong><\/td><\/tr><tr><td>u<\/td><td>Owner<\/td><\/tr><tr><td>g<\/td><td>Group<\/td><\/tr><tr><td>o<\/td><td>Others<\/td><\/tr><tr><td>a<\/td><td>All user classes (owner, group, and others)<\/td><\/tr><tr><td>+<\/td><td>Add permissions<\/td><\/tr><tr><td>&#8211;<\/td><td>Remove permissions<\/td><\/tr><tr><td>=<\/td><td>Set permissions to the specified values<\/td><\/tr><tr><td>r, w, x<\/td><td>Permissions<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">The symbolic mode is more flexible and descriptive. It gives you more control when changing permissions, as you can edit specific privileges of a user class. Consider this example:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">chmod u+wx,g-x,o=r script.sh<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Let\u2019s break down the symbols to understand what it does:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>u+wx <\/strong>\u2013 adds (<strong>+<\/strong>) write (<strong>w<\/strong>) and execute (<strong>x<\/strong>) permissions to the item\u2019s owner (<strong>u<\/strong>).<\/li>\n\n\n\n<li><strong>g-x <\/strong>\u2013 removes (<strong>&#8211;<\/strong>) the execute (<strong>x<\/strong>) permission over the file from the group (<strong>g<\/strong>).<\/li>\n\n\n\n<li><strong>o=r <\/strong>\u2013 sets (<strong>=<\/strong>) other users\u2019 (<strong>o<\/strong>) permissions over the item to read-only (<strong>r<\/strong>).&nbsp;<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">For instance, if the file&#8217;s initial permissions show as<strong> -r&#8211;rwxrwx<\/strong>, it will become <strong>-rwxrw-r&#8211;<\/strong>.<\/p>\n\n\n\n<h3 class=\"wp-block-heading h-t-title-3\" id=\"h-numeric-octal-mode\">Numeric (octal) mode<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">The numeric mode uses three-digit numbers to determine the new permissions. The first digit represents the owner\u2019s permissions, the second is for the owner\u2019s group, and the third is for other users.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Here are the numbers and their definitions:<\/p>\n\n\n\n<figure tabindex=\"0\" class=\"wp-block-table\"><table class=\"has-fixed-layout\"><tbody><tr><td><strong>Number<\/strong><\/td><td><strong>Definition<\/strong><\/td><\/tr><tr><td>4<\/td><td>Read permission<\/td><\/tr><tr><td>2<\/td><td>Write permission<\/td><\/tr><tr><td>1<\/td><td>Execute permission<\/td><\/tr><tr><td>0<\/td><td>No permission<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">To set multiple permissions, simply add the numbers. For example, <strong>3 (1+2) <\/strong>makes an item executable and writable, while <strong>7 (1+2+4) <\/strong>will grant full privileges over the item.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">For example, this command will set the<strong> script.sh<\/strong> file\u2019s permission to <strong>-rwxrw-r&#8211;<\/strong>:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">chmod 764 script.sh<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Numerical notation is more straightforward than symbolic. However, it is less flexible as you can\u2019t add or remove a certain permission, making it suitable for applying specific settings quickly.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Let\u2019s say an owner can read and write an item, but you want to make it executable. With symbolic, you can add the permission using <strong>u+x<\/strong>. Using numerical, you must add the existing privilege again using <strong>7 <\/strong>instead of only <strong>1<\/strong>.<\/p>\n\n\n\n<h3 class=\"wp-block-heading h-t-title-3\" id=\"h-recursive-permission-changes\">Recursive permission changes<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">The chmod\u2019s <strong>-R<\/strong> option enables the recursive mode, which lets you set new permissions to a folder and all its content using a single command.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">For example, we have a <strong>script <\/strong>folder containing the <strong>subscript1<\/strong> and<strong> subscript2<\/strong> subdirectories, as well as several <strong>.sh<\/strong> files. The structure looks as follows:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">script\/\n\u2502\n\u251c\u2500\u2500 subscript\/\n\u2502  \u2514\u2500\u2500 script1.sh\n\u2502\n\u251c\u2500\u2500subscript2\/\n\u2502\n\u251c\u2500\u2500 script2.sh\n\u2502\n\u2514\u2500\u2500 script3.sh<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Using recursive chmod, we can change permissions of all items above by simply modifying the <strong>script<\/strong> folder like so:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">chmod -R 777 script<\/pre>\n\n\n\n<h2 class=\"wp-block-heading h-t-title-2\" id=\"h-changing-ownership-with-chown-and-chgrp\">Changing ownership with chown and chgrp<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">In Linux, if you create an item, you will be its owner by default. If you belong to a group, all other members will inherit the same permissions. You can change the ownership using the <strong>chown<\/strong> or <strong>chgrp<\/strong> command.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Chown is the more common command, which lets you change the ownership to both users and groups. The syntax looks as follows:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">chown [options] [user:group] [item]<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">For example, if you want to change the ownership of <strong>script.sh<\/strong> to <strong>johndoe<\/strong>, who belongs to the <strong>admins<\/strong> group, use the following command:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">chown johndoe:admins script.sh<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">To grant ownership to a new user while keeping the current group, simply omit the group name like so:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">chown johndoe script.sh<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Similarly, omit the user if you wish to change an item\u2019s ownership to another group. However, ensure to start the group name with a colon (<strong>:<\/strong>) similar to this:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">chown :admins script.sh<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The chown command also lets you add the <strong>-R<\/strong> option to change the item ownership recursively:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">chmod -R johndoe:admins scriptfolder<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Unlike chown, chgrp only lets you change an item\u2019s ownership to another group. Here\u2019s an example command:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">chgrp admins script.sh<\/pre>\n\n\n\n<h2 class=\"wp-block-heading h-t-title-2\" id=\"h-special-permission-bits\">Special permission bits<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">In addition to read, write, and execute, Linux has additional permissions that give you more control over items on your system. This section will explain what they are and how to set them up.<\/p>\n\n\n\n<h3 class=\"wp-block-heading h-t-title-3\" id=\"h-setuid-and-setgid\">Setuid and setgid<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Set user ID<\/strong> (setuid) permission lets you execute a file as the owner instead of the current user. You can add it using the <strong>s <\/strong>character of the symbolic notation like so:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">chmod u+s script.sh<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">For example, if <strong>root <\/strong>is the owner of<strong> script.sh<\/strong>, executing the file will run it as <strong>root<\/strong> even if you are logged in as another user. This behavior is useful for launching a program as a specific user, especially during automation.<\/p>\n\n\n<div class=\"announcement-block announcement-block--important\">\n            <span class=\"announcement-block__heading\">\n                <svg aria-hidden=\"true\" width=\"24\" height=\"24\" viewBox=\"0 0 24 24\" fill=\"none\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n                    <path fill-rule=\"evenodd\" clip-rule=\"evenodd\"\n                          d=\"M12 22.5C17.799 22.5 22.5 17.799 22.5 12C22.5 6.20101 17.799 1.5 12 1.5C6.20101 1.5 1.5 6.20101 1.5 12C1.5 17.799 6.20101 22.5 12 22.5ZM13.637 7.65198C13.637 6.74791 12.9041 6.01501 12 6.01501C11.0959 6.01501 10.363 6.74791 10.363 7.65198C10.5335 9.53749 10.875 13.383 10.875 13.383C10.875 14.0043 11.3787 14.508 12 14.508C12.6213 14.508 13.125 14.0043 13.125 13.383V13.38L13.637 7.65198ZM11.9927 15.714C11.3714 15.714 10.8677 16.2177 10.8677 16.839C10.8677 17.4603 11.3714 17.964 11.9927 17.964H12.0073C12.6286 17.964 13.1323 17.4603 13.1323 16.839C13.1323 16.2177 12.6286 15.714 12.0073 15.714H11.9927Z\"\n                          fill=\"#FEA419\"\/>\n                <\/svg>\n                Important\n            <\/span>\n            <p class=\"announcement-block__content\">\n                <strong>Important!<\/strong><br \/>\nYour current user who will run the program must have the execute permission over the file. You can grant it by modifying the group or other user classes.\n            <\/p><\/div>\n\n\n\n<p class=\"wp-block-paragraph\">After adding the <strong>s<\/strong> permission, the file owner\u2019s privilege should show as <strong>rws<\/strong>. It is essentially the same as <strong>rwx<\/strong>, but indicates that setuid is active. The correct setuid permission might look like this:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">-rwsr-xr-x<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Set group ID <\/strong>(setgid) is similar to setuid, except it runs files using the associated group\u2019s permissions. To grant it, use the following command:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">chmod g+s script.sh<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Like setuid, the account that runs the file should have the execute permission as the owner or other users. Setgid permissions might look like this:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">-rwxr-sr-x<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">When you create a new file inside a folder with setgid, the associated group will have ownership permission over it. Typically, your group will own the new file.<\/p>\n\n\n\n<h3 class=\"wp-block-heading h-t-title-3\" id=\"h-sticky-bit\">Sticky bit<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">By default, all users with write permissions over a folder can rename and delete files inside it. This behavior is risky since they might accidentally remove important items.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Sticky bit<\/strong> prevents this by disallowing users to delete or rename files unless they are the owner. Setting it up won\u2019t revoke the write permission, meaning users can modify the file\u2019s content.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">To enable sticky bit on a folder, add the <strong>t<\/strong> permission using the chmod symbolic mode like so:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">chmod +t folder<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The <strong>t<\/strong> permission will replace other users\u2019 execute privileges. Here\u2019s an example of a folder\u2019s permission with sticky bit enabled:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">drwxrwxrwt<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">You can also add sticky bit recursively to all subfolders and files inside a folder by adding the<strong> -R<\/strong> option like so:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">chmod -R +t folder<\/pre>\n\n\n\n<h2 class=\"wp-block-heading h-t-title-2\" id=\"h-conclusion\">Conclusion<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Setting the proper permissions and ownership of items is crucial for server security and functionality. In Linux, you can grant <strong>read,<\/strong> <strong>write<\/strong>, and <strong>execute<\/strong> permissions to three user classes: <strong>owner<\/strong>, <strong>group<\/strong>, and <strong>others<\/strong>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">To change permissions in Linux, use <strong>chmod <\/strong>followed by the settings and items you want to modify. For the setting, use symbolic notation if you want more flexibility in changing the permissions or numerical if you want a simpler command.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Meanwhile, use <strong>chown<\/strong> to change an item\u2019s ownership to another user or group. To modify the group ownership, you can also use the<strong> chgrp<\/strong> command.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">In addition to the three permissions, Linux also has special ones. For example, <strong>setuid <\/strong>and <strong>setgid <\/strong>let you run a file as the owner or associated group. You can also add them using the <strong>chmod<\/strong> command.<\/p>\n\n\n\n<h2 class=\"wp-block-heading h-t-title-2\" id=\"h-change-permissions-linux-faq\">Change permissions Linux FAQ<\/h2>\n\n\n\n<div class=\"schema-faq wp-block-yoast-faq-block\"><div class=\"schema-faq-section\" id=\"faq-question-1733916678452\"><h3 class=\"schema-faq-question\">What command is used to change permissions in Linux?<\/h3> <p class=\"schema-faq-answer\">To change a file or folder\u2019s permissions in Linux, use the <strong>chmod <\/strong>command. The syntax is <strong>chmod [option] [mode] [item]<\/strong>. Option modifies your command behavior, mode specifies the new permissions, while item refers to the file or folder you want to modify.<\/p> <\/div> <div class=\"schema-faq-section\" id=\"faq-question-1733916699510\"><h3 class=\"schema-faq-question\">How do I view the current permissions of a file?<\/h3> <p class=\"schema-faq-answer\">To view the current permissions of a file, run <strong>ls -l filename<\/strong>, with filename being the actual name of the file you want to check. You can also run<strong> ls -l <\/strong>to see permissions of all files and folders in the current directory.<\/p> <\/div> <div class=\"schema-faq-section\" id=\"faq-question-1733916710580\"><h3 class=\"schema-faq-question\">What does chmod stand for in Linux?<\/h3> <p class=\"schema-faq-answer\">In Linux, the <strong>chmod <\/strong>command stands for <strong>change mode<\/strong>. It lets you modify a file or folder&#8217;s permission, allowing different users to read, write, or execute it.<\/p> <\/div> <\/div>\n\n\n\n<h3 class=\"wp-block-heading h-t-title-3\" id=\"h-\"><\/h3>\n","protected":false},"excerpt":{"rendered":"<p>Properly managing Linux file permissions and ownership is essential for safety, especially when multiple administrators manage one server. Moreover, using [&#8230;]<\/p>\n<p><a class=\"btn btn-secondary understrap-read-more-link\" href=\"\/tutorials\/how-to-change-linux-permissions-and-owners\/\">Read More&#8230;<\/a><\/p>\n","protected":false},"author":337,"featured_media":118890,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"rank_math_title":"How to change file permissions in Linux using chmod","rank_math_description":"To change permissions in Linux, run chmod followed by the new permission setting and the item you want to modify. Read on to learn more about it.","rank_math_focus_keyword":"change permissions linux","_content_updated_date":"2024-12-11","footnotes":""},"categories":[22648,22644],"tags":[],"class_list":["post-665","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-managing-monitoring-and-security","category-vps"],"hreflangs":[{"locale":"en-US","link":"https:\/\/www.hostinger.com\/tutorials\/how-to-change-linux-permissions-and-owners","default":0},{"locale":"pt-BR","link":"https:\/\/www.hostinger.com\/br\/tutoriais\/como-alterar-permissoes-e-proprietarios-via-linha-de-comando","default":0},{"locale":"fr-FR","link":"https:\/\/www.hostinger.com\/fr\/tutoriels\/changer-permissions-fichier-linux\/","default":0},{"locale":"es-ES","link":"https:\/\/www.hostinger.com\/es\/tutoriales\/cambiar-permisos-y-propietarios-linux-linea-de-comandos\/","default":0},{"locale":"id-ID","link":"https:\/\/www.hostinger.com\/id\/tutorial\/pengertian-chmod-dan-chown-untuk-permission-di-linux\/","default":0},{"locale":"en-PH","link":"https:\/\/www.hostinger.com\/ph\/tutorials\/how-to-change-linux-permissions-and-owners\/","default":0},{"locale":"en-MY","link":"https:\/\/www.hostinger.com\/my\/tutorials\/how-to-change-linux-permissions-and-owners","default":0},{"locale":"en-GB","link":"https:\/\/www.hostinger.com\/uk\/tutorials\/how-to-change-linux-permissions-and-owners","default":0},{"locale":"en-IN","link":"https:\/\/www.hostinger.com\/in\/tutorials\/how-to-change-linux-permissions-and-owners","default":0},{"locale":"en-CA","link":"https:\/\/www.hostinger.com\/ca\/tutorials\/how-to-change-linux-permissions-and-owners\/","default":0},{"locale":"en-AU","link":"https:\/\/www.hostinger.com\/au\/tutorials\/how-to-change-linux-permissions-and-owners","default":0},{"locale":"en-NG","link":"https:\/\/www.hostinger.com\/ng\/tutorials\/how-to-change-linux-permissions-and-owners\/","default":0},{"locale":"es-AR","link":"https:\/\/www.hostinger.com\/ar\/tutoriales\/cambiar-permisos-propietarios-linux-traves-la-linea-comandos\/","default":0},{"locale":"es-MX","link":"https:\/\/www.hostinger.com\/mx\/tutoriales\/cambiar-permisos-propietarios-linux-traves-la-linea-comandos\/","default":0},{"locale":"es-CO","link":"https:\/\/www.hostinger.com\/co\/tutoriales\/cambiar-permisos-propietarios-linux-traves-la-linea-comandos\/","default":0},{"locale":"pt-PT","link":"https:\/\/www.hostinger.com\/pt\/tutoriais\/como-alterar-permissoes-e-proprietarios-via-linha-de-comando","default":0}],"_links":{"self":[{"href":"https:\/\/www.hostinger.com\/tutorials\/wp-json\/wp\/v2\/posts\/665","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.hostinger.com\/tutorials\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.hostinger.com\/tutorials\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.hostinger.com\/tutorials\/wp-json\/wp\/v2\/users\/337"}],"replies":[{"embeddable":true,"href":"https:\/\/www.hostinger.com\/tutorials\/wp-json\/wp\/v2\/comments?post=665"}],"version-history":[{"count":29,"href":"https:\/\/www.hostinger.com\/tutorials\/wp-json\/wp\/v2\/posts\/665\/revisions"}],"predecessor-version":[{"id":127304,"href":"https:\/\/www.hostinger.com\/tutorials\/wp-json\/wp\/v2\/posts\/665\/revisions\/127304"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.hostinger.com\/tutorials\/wp-json\/wp\/v2\/media\/118890"}],"wp:attachment":[{"href":"https:\/\/www.hostinger.com\/tutorials\/wp-json\/wp\/v2\/media?parent=665"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.hostinger.com\/tutorials\/wp-json\/wp\/v2\/categories?post=665"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.hostinger.com\/tutorials\/wp-json\/wp\/v2\/tags?post=665"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}