Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What are the permissions of linux files and how to modify them?

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)05/31 Report--

This article mainly introduces the relevant knowledge of "what are the linux file permissions and how to modify them". Xiaobian shows you the operation process through actual cases. The operation method is simple and fast and practical. I hope this article "what are the linux file permissions and how to modify them" can help you solve the problem.

Linux file permissions have 7 kinds: 1, r permissions, that can read the contents of the file;2, w permissions, that can modify the contents of the file;3, x permissions;4, rw permissions, that can read and write to the file;5, wx permissions;6, rx permissions, that can read the file and can execute;7, rwx permissions, that can read and write, execute.

This tutorial operates on Linux 5.9.8 and Dell G3 computers.

First of all, if we want to manage the permissions of users, we must know how to view the permissions of a file. We can use the ll command or ls -l command to view the permissions of a file, as shown below:

We can see that using the ll command lists some information about the files under/app, a total of 7 columns, these 7 columns represent the details of the files under/app:

(1)The first column has a total of 11 characters, the first bit shows the file type, linux files are divided into 7 categories:

1.- Common file 2.d Directory file 3.b Block device file 4.c Character device 5.l Symbolic link file 6.p pipe file 7.s suite word file

This is 7 different file types under linux, and then the next 9 bits are the permissions we will introduce, these 9 bits are divided into 3 groups, each group of 3 bits, each has two cases, as shown in the above figure, the first group is rwx, representing readable, writable and executable, if r represents readable, if it is-it means unreadable, w represents writable, -represents unwritable, x represents executable, -represents unexecutable. The first group 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 others. The last one. Selinux is enabled, so I won't repeat it here.

 (2)The second column has only one number, which indicates the number of links in the file. The above 3 indicates that the file has three links.

 (3)The third column indicates the owner of the file, i.e. the name of the owner. As above, root means that the file belongs to the user root.

 (4)The fourth column indicates the names of all groups of files, i.e., group names. As above, root indicates that the file belongs to the root group.

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

 (6)The sixth column indicates when the file was updated.

 (7)The seventh column indicates the file name

file permissions

The operations we can implement on files are nothing more than read, write, execute, and their combination permissions: create, delete, modify (can write naturally can modify);3-bit permissions, nothing more than r, w, x, rw, rx, wx, rwx.

There are 7 types of file permissions:

R permission: indicates that the contents of the file can be read, using cat or less.

W permission: means that you can modify the contents of the file, using vim, vi, etc.

X Permission: Has no effect.

rw permission: 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 permission: means readable, writable, executable, highest permission.

How to modify permissions, who has the right to modify the file or directory permissions?

Changing permissions is done with the chmod command.

chmod u+/-r/x/w/rx/rw/wx/rwx + filename modify permissions on group chmod g+/-r/x/w/rx/rw/wx/rwx + filename Modify permissions for other users chmod o+/r/x/w/rx/rw/wx/rwx + filename

At the same time we can also use binary method to express file permissions. For each set of permissions, there are only two possibilities for each bit, yes or no, and we can use 1 for yes and 0 for no. It would look something like this:

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

Because permissions can be expressed numerically, we have an easier way to change file permissions:

chmod 777 /app/house

Or chmod numeric permissions plus file, so you can change all permissions of the file at once.

**    Experiment to see who can modify file permissions, root user is super user, is able to modify all permissions, here no longer experiment **.

   Now create user liubei,guanyu,zhangfei,caocao, create group shuguo, set group administrator to guanyu, set group members to liubei,guanyu,caocao; create directory test under app, modify permissions to 777, modify belonging group to shuguo, switch user to Liu Bei, create a test.file under/test, command as follows:

useradd liubeiuseradd guanyuuseradd zhangfeiuseradd caocaogroupadd shuguogpasswd -A guanyu shuguogpasswd -M liubei,guanyu,zhangfeicd /appmkdir testchmod 777 testsu - liubeicd /app/testtouch test.filell

The results are as follows:

Now liubei is owner of test.file, guanyu is administrator of group sanguo, liubei,zhangfei,guanyu is group member of shuguo, caocao is other Now test owner, group member, group administrator, can others modify permissions of test.file.

Liubei is the owner:

guanyu is shuguo's group management

zhangfei is a member of shuguo's group

caocao is not a member of shuguo's group

It follows that only root and the owner of the file can modify the permissions of the file, and no one else can modify it.

About "linux file permissions what and how to modify" the content is introduced here, thank you for reading. If you want to know more about industry-related knowledge, you can pay attention to the industry information channel. Xiaobian will update different knowledge points for you every day.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report