{"id":22087,"date":"2023-10-01T16:21:32","date_gmt":"2023-10-01T16:21:32","guid":{"rendered":"https:\/\/linuxways.net\/?p=22087"},"modified":"2023-10-01T16:21:32","modified_gmt":"2023-10-01T16:21:32","slug":"how-to-change-file-permissions-and-ownership-in-linux-ubuntu","status":"publish","type":"post","link":"https:\/\/linuxways.net\/de\/ubuntu\/how-to-change-file-permissions-and-ownership-in-linux-ubuntu\/","title":{"rendered":"How to Change File Permissions and Ownership in Linux\/Ubuntu?"},"content":{"rendered":"<p><strong>Linux\/Ubuntu <\/strong>is a multi-user Operating System, i.e., multiple users can share system resources at once. Linux controls access to these shared system resources by managing the <strong>Permission <\/strong>and <strong>ownership <\/strong>of files and directories. This article will demonstrate ways of changing permissions and ownership of files on Linux\/Ubuntu 22.04 LTS as below:<\/p>\n<ul>\n<li>Changing File Permissions.<\/li>\n<\/ul>\n<h2><a id=\"post-22087-_36mp1al0cp1g\"><\/a>Changing File Ownership.<\/h2>\n<h3><a id=\"post-22087-_z59hpa8br4y\"><\/a>How to Change File Permissions in Linux\/Ubuntu?<\/h3>\n<p>In this section, we will discuss file permissions in Linux\/Ubuntu systems. For example, file permissions of \u201cSampleFile.txt\u201d can checked by:<\/p>\n<div class=\"codecolorer-container bash blackboard\" style=\"width:100%;\"><div class=\"bash codecolorer\"><span class=\"co4\">$ <\/span><span class=\"kw2\">ls<\/span> <span class=\"re5\">-l<\/span><\/div><\/div>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"2048\" height=\"210\" class=\"wp-image-22101\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22087-1.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22087-1.png 2048w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22087-1-300x31.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22087-1-1024x105.png 1024w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22087-1-768x79.png 768w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22087-1-1536x158.png 1536w\" sizes=\"auto, (max-width: 2048px) 100vw, 2048px\" \/><\/p>\n<p>From the above image, we can see that the file permission of file \u201cSampleFile.txt\u201d is \u201c-rw-rw-r\u2013\u201d. The first set is the user permission, the second set is of the group of users&#8217; permission, and the third set consists of other users&#8217; permissions as shown below:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"2048\" height=\"480\" class=\"wp-image-22112\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22087-2.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22087-2.png 2048w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22087-2-300x70.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22087-2-1024x240.png 1024w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22087-2-768x180.png 768w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22087-2-1536x360.png 1536w\" sizes=\"auto, (max-width: 2048px) 100vw, 2048px\" \/><\/p>\n<h3><\/h3>\n<p>There are three types of owners:<\/p>\n<ul>\n<li><strong>User(u):<\/strong> Owner of the file.<\/li>\n<li><strong>Group(g):<\/strong> Collection of users. In Linux, permissions are assigned in bulk, i.e., all users in the group have permission to access a file.<\/li>\n<li><strong>Other(o): <\/strong>Any user that is not part of the above two groups (i.e., everyone else).<\/li>\n<\/ul>\n<h3><\/h3>\n<p>Additionally, there are three permission categories in each owner category:<\/p>\n<ul>\n<li><strong>Read (r): <\/strong>Read permissions grants the read access to the user, i.e. the user can access the files and see the content.<\/li>\n<li><strong>Write (w): <\/strong>Write permissions that allow the user to edit, save, and delete files.<\/li>\n<li><strong>Execute (x): <\/strong>Execute permissions allow the user to run the file.<\/li>\n<\/ul>\n<p>The chmod command is frequently used for changing the file permissions. The general syntax of chmod command is<\/p>\n<div class=\"codecolorer-container bash blackboard\" style=\"width:100%;\"><div class=\"bash codecolorer\"><span class=\"co4\">$ <\/span><span class=\"kw2\">chmod<\/span> <span class=\"sy0\">&lt;<\/span>permissions<span class=\"sy0\">&gt;<\/span> <span class=\"sy0\">&lt;<\/span>filename<span class=\"sy0\">&gt;<\/span><\/div><\/div>\n<p>where:<\/p>\n<ul>\n<li>Permissions: File permissions, i.e., read, write, and executable permissions, or a combination of these permissions for a user group.<\/li>\n<li>Filename: Name of the file whose permissions are required to be changed.<\/li>\n<\/ul>\n<p>The file permissions can be changed by the following methods using chmod command:<\/p>\n<ul>\n<li>Symbolic Mode<\/li>\n<li>Absolute Mode<\/li>\n<\/ul>\n<h3><a id=\"post-22087-_y8kt99klgnp2\"><\/a>How to Change File Permissions Using Symbolic Mode?<\/h3>\n<p>In chmod command, we use a combination of \u201cfile owners\u201d, i.e., user(u), group(g), others(o), and mathematical operator in &lt;permissions&gt; while using symbolic code:<\/p>\n<ul>\n<li><strong>+<\/strong>: Adds permission to a file.<\/li>\n<li><strong>&#8211;<\/strong>: Remove a certain permission.<\/li>\n<li><strong>=<\/strong>: Assigns the permission to the file.<\/li>\n<\/ul>\n<p>For example, below is an example of changing user permissions of a SampleFile.txt:<\/p>\n<div class=\"codecolorer-container bash blackboard\" style=\"width:100%;\"><div class=\"bash codecolorer\"><span class=\"co4\">$ <\/span><span class=\"kw2\">chmod<\/span> u+x SampleFile.txt<\/div><\/div>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"2048\" height=\"423\" class=\"wp-image-22124\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22087-3.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22087-3.png 2048w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22087-3-300x62.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22087-3-1024x212.png 1024w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22087-3-768x159.png 768w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22087-3-1536x317.png 1536w\" sizes=\"auto, (max-width: 2048px) 100vw, 2048px\" \/><\/p>\n<p>From the above image, it can be seen that user permission is modified from \u201c-rw-rw-r\u2013\u201d to \u201c-rwxrw-r\u2013\u201d, i.e., execution permissions are added to file owner (u).<\/p>\n<h3><a id=\"post-22087-_iuqmkwg3v7n2\"><\/a>How to Change File Permissions Using Absolute Mode?<\/h3>\n<p>In this, Real Numbers represent permissions. In absolute mode, permissions are added by adding 4, 2,1 for read, write, and execute respectively while permissions are revoked by subtracting 4, 2, 1 respectively for each file owner, i.e., the user(u), group(g), others(o). For example, we can view the file permissions of \u201cSampleFile.txt\u201d as follows:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"2048\" height=\"161\" class=\"wp-image-22131\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22087-4.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22087-4.png 2048w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22087-4-300x24.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22087-4-1024x81.png 1024w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22087-4-768x60.png 768w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22087-4-1536x121.png 1536w\" sizes=\"auto, (max-width: 2048px) 100vw, 2048px\" \/><\/p>\n<p>In the above image, the permission of \u201cSampleFile.txt\u201d is \u201c-rwxrw-r\u2013\u201d. We will change file permission to \u201c-rw-rw-r\u2013\u201d by running the following command:<\/p>\n<div class=\"codecolorer-container bash blackboard\" style=\"width:100%;\"><div class=\"bash codecolorer\"><span class=\"co4\">$ <\/span><span class=\"kw2\">chmod<\/span> <span class=\"nu0\">664<\/span> SampleFile.txt<\/div><\/div>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"2048\" height=\"419\" class=\"wp-image-22143\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22087-5.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22087-5.png 2048w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22087-5-300x61.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22087-5-1024x210.png 1024w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22087-5-768x157.png 768w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22087-5-1536x314.png 1536w\" sizes=\"auto, (max-width: 2048px) 100vw, 2048px\" \/><\/p>\n<p>From the above image, the permission is changed to \u201c-rw-rw-r\u2013\u201d, i.e., the execution permission for file owner (u) is revoked. Additionally, 664 is calculated by:<\/p>\n<ul>\n<li>The first digit (6) is the sum of read (4) and write (2) permission for the user.<\/li>\n<li>The second digit (6) is the sum of read (4) and write (2) permission for the users of the group.<\/li>\n<li>The third digit (4) is the sum of read (4) permission for others.<\/li>\n<\/ul>\n<h3><a id=\"post-22087-_3ptqymttyzp3\"><\/a>How to Change File Ownership in Linux?<\/h3>\n<p>File ownership is modified using the <strong>chown<\/strong> command<strong>. <\/strong>The general syntax of chown is<\/p>\n<div class=\"codecolorer-container bash blackboard\" style=\"width:100%;\"><div class=\"bash codecolorer\"><span class=\"co4\">$ <\/span><span class=\"kw2\">sudo<\/span> <span class=\"kw2\">chown<\/span> <span class=\"sy0\">&lt;&lt;<\/span>strong<span class=\"sy0\">&gt;<\/span>user<span class=\"sy0\">&lt;\/<\/span>strong<span class=\"sy0\">&gt;&gt;<\/span> <span class=\"sy0\">&lt;&lt;<\/span>strong<span class=\"sy0\">&gt;<\/span>filename<span class=\"sy0\">&lt;\/<\/span>strong<span class=\"sy0\">&gt;&gt;<\/span><\/div><\/div>\n<p>Where<\/p>\n<ul>\n<li>user: the name of the user.<\/li>\n<li>filename: The name of the file in String.<\/li>\n<\/ul>\n<p>In our case, the ownership of a file \u201cSampleFile.txt\u201d will be changed. We can check the current ownership by running the following command:<\/p>\n<div class=\"codecolorer-container bash blackboard\" style=\"width:100%;\"><div class=\"bash codecolorer\"><span class=\"co4\">$ <\/span><span class=\"kw2\">ls<\/span> <span class=\"re5\">-l<\/span><\/div><\/div>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"2048\" height=\"209\" class=\"wp-image-22148\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22087-6.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22087-6.png 2048w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22087-6-300x31.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22087-6-1024x105.png 1024w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22087-6-768x78.png 768w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22087-6-1536x157.png 1536w\" sizes=\"auto, (max-width: 2048px) 100vw, 2048px\" \/><\/p>\n<p>In the above image, we can see the file \u201cSampleFile.txt\u201d is owned by \u201clinuxuser\u201d. The file ownership can be changed from \u201clinuxuser\u201d to \u201croot\u201d user by following the command:<\/p>\n<div class=\"codecolorer-container bash blackboard\" style=\"width:100%;\"><div class=\"bash codecolorer\"><span class=\"co4\">$ <\/span><span class=\"kw2\">sudo<\/span> <span class=\"kw2\">chown<\/span> root SampleFile.txt<\/div><\/div>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"2048\" height=\"406\" class=\"wp-image-22154\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22087-7.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22087-7.png 2048w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22087-7-300x59.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22087-7-1024x203.png 1024w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22087-7-768x152.png 768w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22087-7-1536x305.png 1536w\" sizes=\"auto, (max-width: 2048px) 100vw, 2048px\" \/><\/p>\n<p>The above image indicates that the owner of \u201cSampleFile.txt\u201d is modified from \u201clinuxuser\u201d to \u201croot\u201d<\/p>\n<h2><a id=\"post-22087-_k4r3ojha6hv3\"><\/a>Conclusion<\/h2>\n<p>To change file permissions and ownership in Linux\/Ubuntu, use the \u201cchmod &lt;permissions&gt; &lt;filename&gt;\u201d and \u201csudo chown &lt;user&gt; &lt;filename&gt;\u201d commands. This article demonstrated two ways of changing permissions, i.e., by using symbolic mode and by using absolute mode. Additionally, changing the ownership of files on Linux\/Ubuntu 22.04 LTS is also discussed.<\/p>\n<p>&nbsp;<\/p>","protected":false},"excerpt":{"rendered":"<p>To change file permissions and ownership in Linux\/Ubuntu, use the \u201cchmod <permissions> <filename>\u201d and \u201csudo chown <user> <filename>\u201d commands.<\/p>","protected":false},"author":110,"featured_media":22198,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1049,2],"tags":[],"class_list":["post-22087","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-linux-commands","category-ubuntu"],"_links":{"self":[{"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/posts\/22087","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/users\/110"}],"replies":[{"embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/comments?post=22087"}],"version-history":[{"count":0,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/posts\/22087\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/media\/22198"}],"wp:attachment":[{"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/media?parent=22087"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/categories?post=22087"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/tags?post=22087"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}