Home  >  Article  >  Operation and Maintenance  >  What are the types of linux file permissions?

What are the types of linux file permissions?

青灯夜游
青灯夜游Original
2022-03-09 13:20:0766482browse

There are 7 types of Linux file permissions: 1. r permission, which means you can read the contents of the file; 2. w permission, which means you can modify the contents of the file; 3. x permission; 4. rw permission, which means you can Read and write the file; 5. wx permission; 6. rx permission, which means the file can be read and executed; 7. rwx permission, which means it can read, write, and execute.

What are the types of linux file permissions?

#The operating environment of this tutorial: linux7.3 system, Dell G3 computer.

First of all, if we want to manage user permissions, we must know how to check the permissions of a file. We can use the ll command or the ls -l command to check the permissions of a file, as follows Figure:

What are the types of linux file permissions?

We can see that using the ll command lists some information about the files under /app. There are 7 columns in total. These 7 columns represent the detailed information of the files under /app. :

(1) There are 11 characters in the first column. The first column shows the file type. There are 7 categories of files under Linux:

 1.-  普通文件
 2.d  目录文件
 3.b  块设备文件
 4.c  字符设备
 5.l   符号链接文件
 6.p 管道文件
 7.s 套件字文件

This is 7 types under Linux Different file types, and then the next 9 digits are the permissions we are going to introduce. These 9 digit permissions are divided into 3 groups, each group has 3 digits. There are two situations for each one, as shown in the picture above, the first group is rwx, It means readable, writable and executable. If r means readable, - means unreadable, w means writable, - means unwritable, x means executable, and - means not executable. The first group of these three sets of permissions represents the permissions of the file owner, the second group represents the permissions of the file owner group, and the third group represents the permissions of other people. The last . indicates enabling selinux, which I won’t go into details here.

(2) The second column has only one number, indicating the number of connections to the file. The above 3 means that the file has three links.

(3) The third column represents the owner of the file, that is, the name of the owner. As shown above, root means that the file belongs to the root user.

(4) The fourth column represents all the groups of the file, that is, the name of the group. As shown above, root means that the file belongs to the root group.

 (5)The fifth column indicates the size of the file.

 (6)The sixth column indicates the update time of the file.

(7) The seventh column represents the file name

File permissions

#The operations we can perform on files are nothing more than reading, writing, and executing. And their combined permissions: create, delete, modify (if you can write, you can modify it naturally); the 3-digit permissions are nothing more than the combination of r, w, x, rw, rx, wx, and rwx.

There are 7 types of file permissions:

  • r permission: indicates that the content of the file can be read, use cat or less.

  • w Permission: Indicates that the content of the file can be modified, using vim, vi, etc.

  • xPermissions: No effect.

  • rw permissions: Indicates that the file can be read and written.

  • wx permission: equivalent to w permission, can only write.

  • rx permission: indicates that the file can be read and executed.

  • rwx permissions: indicates readable, writable, and executable, which is the highest permission.

#How to modify permissions? Who has the right to modify the permissions of files or directories?

Modifying permissions is done through the chmod command.

对所有者权限修改 chmod u+/-r/x/w/rx/rw/wx/rwx +文件名
对群组权限修改     chmod g+/-r/x/w/rx/rw/wx/rwx +文件名
对其他用户权限修改 chmod o+/r/x/w/rx/rw/wx/rwx +文件名

At the same time, we can also use binary methods to represent file permissions. For each set of permissions, there are only two possibilities for each bit, that is, yes or no. We can use 1 to mean yes and 0 to mean no. It will look like this:

r-- 100 =4
\-w- 010 =2
\--x 001 =1
rw- 110 =6
r-x 101 =5
\-wx 011=3
rwx 111=7
\--- 000 =0

Because numbers can be used to represent permissions, then we have an easier way to change file permissions:

chmod 777 /app/house

or chmod the permissions represented by numbers. Add files so that all permissions of the files can be changed at once.

**  Experiment to see who can modify the permissions of the file. The root user is a super user and can modify all permissions. There will be no further experiments** here.

 Now we are creating users liubei, guanyu, zhangfei, caocao, creating group shuguo, setting the group administrator as guanyu, and setting the group members as liubei, guanyu, caocao; create the directory test under the app. Modify the permissions to 777, modify the group to shuguo, switch the user to Liu Bei, create a test.file under /test, the command is as follows:

useradd liubei
useradd guanyu
useradd zhangfei
useradd caocao
groupadd shuguo
gpasswd -A guanyu shuguo
gpasswd -M liubei,guanyu,zhangfei
cd /app
mkdir test
chmod 777 test
su - liubei
cd /app/test
touch test.file
ll

The result is as shown below:

What are the types of linux file permissions?

What are the types of linux file permissions?

##Now liubei is the owner of test.file, guanyu is the administrator of group sanguo, liubei, zhangfei, guanyu are group members of shuguo, caocao is other and the current test owner. Can group members, group administrators, and others modify the permissions of test.file.

liubei is the owner:

What are the types of linux file permissions?##guanyu is shuguo’s group manager

What are the types of linux file permissions?zhangfei is shuguo’s Group members

What are the types of linux file permissions?

caocao is not a member of shuguo’s group

What are the types of linux file permissions?

It can be seen that only root and the owner of the file can modify the permissions of the file, others No one can modify it.

Related recommendations: "Linux Video Tutorial"

The above is the detailed content of What are the types of linux file permissions?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn