linux view folder permissions

Three, Linux file permissions

First, let's check the contents of the files in the current directory.

ls -l    查看当前目录下的文件列表
ls -l xxx.xxx (xxx.xxx是文件名) 查看指定的文件

img

We can see the file permissions, -rw-rw-r-- , which has a total of 10 digits.

Among them: the front one-represents the type (detailed as shown in the texture below)

The three rw- in the middle represent the owner (user)

Then those three rw- represent groups (group)

The last three r-- represent other people (other)

Then I will explain the next 9 digits:

r means the file can be read (read)

w means the file can be written (write)

x means the file can be executed (if it is a program)

-Indicates that the corresponding permissions have not been granted

File and folder operation permissions:

Authority Shorthand Effect on ordinary files Effect on folders
Read r View file content List files in a folder (ls)
Write w Modify file content Delete, add or rename files (folders) in the folder
carried out x File can be executed as a program cd to folder

Illustration:

img

img

One thing to note is that a directory has both read and execute permissions to open and view internal files, while a directory must have write permissions to allow other files to be created in it. This is because the directory file actually stores the files in the directory. List of files and other information.

supplement:

Special permissions SUID, SGID, Sticky There are three file permissions attributes in the Linux system that have nothing to do with user identity. Namely SUID, SGID and Sticky. SUID (Set User ID, 4): This attribute is only valid for files with execution permission, not for directories. When executing a program with SUID permissions, the owner of the triggered process is the owner of the program file, not the user who started the program (unless the two are the same person). For example, if the owner of a program is root and has the SUID attribute, when an ordinary user executes the program, it is the same as root executes the program. (Please note that this attribute is invalid for Shell script programs) This attribute brings convenience to the startup of some special programs (such as lpr). But sometimes it also brings security risks: For example, if a program with SUID attributes runs a shell during execution, the user can get the highest authority of the system. SUID can be represented by s , such as: $ ls -l /usr/bin/passwd -rw s r-xr-x 1 root root 47032 Feb 16 2014 /usr/bin/passwd

SGID(Set Group ID, 4):

For executable files, SGID is similar to SUID, and all groups of the triggered process are the groups to which the program file belongs. For directories, the SGID attribute makes the group of newly created files in the directory the same as the directory. SGID can also be used

s

Means, such as:

$ ls -l / var

drwxrw

s

r-x 2 root staff 4096 Apr 10 2014 local

drwxrwxr-x 15 root syslog 4096 Apr 4 19:57 log

Sticky, 1:

Only valid for directories. Files or directories under the directory with sticky attribute can be deleted or renamed by their owner. The sticky attribute is often used to create such directories: group users can create new files in this directory, modify the contents of the files, but only the file owner can delete or rename their own files. Such as the /tmp folder in the system. In the attribute string, usually use

t

Said.

$ ls -l /

drwxrwxrw

t

8 root root 4096 Apr 4 23:57 tmp

Modify the operating permissions of the users corresponding to files and folders

If you have a file of your own that you don't want to be read, written, or executed by other users, you need to modify the file permissions. There are two ways:

Method 1: Binary digital representation

img

Three groups of permissions for each file: u stands for the owner ( user ) g stands for the owner's group ( group ) o stands for others, but not u and g ( other ) a stands for all people, that is, including u, g and o are based on the above figure, where: rwx can also be replaced by numbers for r ------------4w -----------2x -------- ----1- ------------0

After everyone understands the above things, then we can easily understand some of the following common permissions: -rw------- (600) Only the owner has read and write permissions -rw- r--r-- (644) Only the owner has read and write permissions, and the group and others have only read permissions -rwx------ (700) Only the owner has read, write, and execute permissions Permissions-rwxr-xr-x (755) Only the owner has read, write, and execute permissions. Groups and others have only read and execute permissions-rwx--x--x (711) Only the owner There are read, write, and execute permissions. Groups and others have only execute permissions -rw-rw-rw- (666) Everyone has read and write permissions -rwxrwxrwx (777) Everyone has read, write and execute permissions Authority

Actual operation

Check the permissions of test, the owner has the permissions to read, write, and execute :

img

Then I added some content to the file, changed the permissions (700: -rwx------), and tried to read the file under shiyanlou (owner), which can be read.

img

Change to another user Peter, and try to read again as shown in the figure below. It shows that the permissions are not enough to read.

img

Method two: addition and subtraction assignment operation

u represents the owner (user) g represents the owner's group (group) o represents other people, but not u and g (other)

a represents all people, that is, including u, g, and o

+ And-respectively indicate adding and removing corresponding permissions. The + sign is generally not displayed ( I still add it when I first learn to practice hands )

Enter in the terminal: chmod o+w xxx.xxx chmod ow xxx.xxx means to grant others the permission to write the file xxx.xxx

chmod go-rw xxx.xxx means to delete the read and write permissions of the group and others in xxx.xxx chmod ug-r xxx.xxx

img

img

Modify the owner/group of a file or folder

Use the chown command to change the ownership (owner/group) of a directory or file

Note: The intermittent ones mentioned here will be added after learning the next content (user/group addition, deletion, modification, and check)

Files and directories can not only change permissions, but their ownership and user groups can also be modified. Similar to setting permissions, users can set them through the graphical interface or execute the chown command to modify them. We first execute ls -l to see the directory situation:

img

You can see that the user group of the test file is root , and the owner is root . Execute the following command to transfer the ownership of the test file in the above figure to user peter : # chown peter test

img

To change the group, transfer the test file from the root group to the group Peter, use the following command: # chown :peter test

img

Change the belonging user and group together. Change the owner of the folder or file test to shiyanlou , and change the group to shiyanlou , as shown below:

img

The above is the Linux-related knowledge shared by Liangxu Tutorial Network for all friends.

Guess you like

Origin blog.csdn.net/manongxianfeng/article/details/113116183