添加链接
link管理
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接
相关文章推荐
千年单身的长颈鹿  ·  SAP ...·  1 月前    · 
腼腆的木耳  ·  IDX10503: Signature ...·  10 月前    · 

[Want to try out Red Hat Enterprise Linux? Download it now for free.]

If you have ever worked Linux system, you for sure have dealt with files, and that means that you might have encountered messages like this one below:

localhost@user1$ cat /etc/sudoers cat: /etc/sudoers: Permission denied

Or, similar to this, error messages like "You do not have the permissions to upload files to this folder," which might have prevented you from reading, writing, or accessing a particular file. And, naturally, this error might have made you wonder—the first time you encountered this problem, at least—as to why you were denied access.

Let’s take a look into Linux file permissions and the ways to restrict them, plus play with files a little bit. When you list files in a particular directory in Linux, you might have seen r, w, and x, and wondered what these letters mean. They have tremendous significance in determining what exactly a particular user can do with a file.

Let’s take a look at an example:

localhost@user1$ ls -ltr chmod_directory/ total 0 -rw-r--r--. 1 creator creator 0 Jul 29 21:55 I_Can_Write.txt -rw-r--r--. 1 creator creator 0 Jul 29 21:55 I_Can_Execute.sh -rw-r--r--. 1 creator creator 0 Jul 29 21:55 I_Can_Access.txt

Default file permissions are rw-r--r-- (from the umask value (covered later in the article)), as shown in the example above.

Each permission has a numeric value assigned to it:

  • r (read) has a value of 4
  • w (write) has a value of 2
  • x (execute) has a value of 1

These values are additive for each "triplet", meaning that a file permission of rw- has the value of 6 and rwx has the value of 7. As discussed above, any file that’s newly created, the default value is 644 (rw-r--r--), meaning that the file’s owner can read and write, and all others can only read this file. The first triplet is the permission for the file owner/creator, the second is for group permissions, and the third is for others (users outside of the owner/creator or a group with permissions). This setting makes sense for obvious reasons: The owner should have higher control over the file’s contents in order to both read and write to it. Others might want to read the contents but not modify them. Of course, you can change this setting with the chmod command, which is the focus of this article.