Interpretation of file permissions under Linux system - (user, group, read, write and execute)

齐天大圣
Release: 2020-09-14 09:29:54
Original
3032 people have browsed it

Often when deploying a website, the code has been uploaded, the database has been imported, and the configuration file has been changed. But when I entered the domain name, I still got an error. The reason was probably due to file permissions. Today let’s take a look at file permissions under Linux

Users, groups

Linux philosophy Everything is a file, and all files will have their own owners , the group it belongs to. Also, any user must definitely belong to a group. Except for the owner of the file and the users in its group, all other users of the system are the others of the file. How to check users under Linux can be done by viewing the /etc/passwd file.

# cat /etc/passwd root:x:0:0:root:/root:/bin/bash bin:x:1:1:bin:/bin:/sbin/nologin daemon:x:2:2:daemon:/sbin:/sbin/nologin adm:x:3:4:adm:/var/adm:/sbin/nologin lp:x:4:7:lp:/var/spool/lpd:/sbin/nologin sync:x:5:0:sync:/sbin:/bin/sync shutdown:x:6:0:shutdown:/sbin:/sbin/shutdown halt:x:7:0:halt:/sbin:/sbin/halt ……
Copy after login

Through the ls -l command, you can view some attributes such as the owner and group of the file.

# ll total 17484 drwxr-xr-x 3 root root 4096 Dec 2 2019 backup drwxr-xr-x 2 root root 4096 May 15 08:32 bin drwxr-xr-x 10 root root 4096 Jan 8 2020 c_language_code drwxr-xr-x 2 root root 4096 Jun 12 10:46 c_practice -rw-r--r-- 1 root mail 8500 Sep 13 03:47 dead.letter
Copy after login

Of course, we can modify the owner and group of the file through commands

# 同时改变用户和组 -R表示递归修改 # chown -R www:www backup # ll -d backup drwxr-xr-x 3 www www 4096 Dec 2 2019 backup # 仅改变用户 # chown -R root backup # ll -d backup drwxr-xr-x 3 root www 4096 Dec 2 2019 backup # 仅改变组 # chown -R :root backup # ll -d backup drwxr-xr-x 3 root root 4096 Dec 2 2019 backup # 还可以通过chgrp改变组 # chgrp -R www backup/
Copy after login

File permissions

Now Let's take a look at the file permissions. The file permissions can also be viewed through ls -l.

drwxr-xr-x
Copy after login

There are 10 characters in total, which can be divided into four groups, d, rwx, r-x, r-x.

  • d indicates the type of the file. Common ones are - (file), d (directory), b (block device)

  • th The second group represents the permissions owned by the user of the file, rwx represents readable, writable, and executable respectively. If replaced by -, it means that you do not have that permission.

  • The third group represents the permissions owned by the group of the file

  • The fourth group represents the permissions owned by other people in the file Permissions

Readable, writable, and executable are a bit abstract, and they have different meanings for different file types. Below, I will make a table to help you understand:

File Directory
r means yes To check the file information, you can use cat/less/more/head/tail and other commands to check the file information r means you can list the file list in the directory, you can execute the ls command
w means that the file content can be modified, and the file content can be modified through vim w means that files can be created or deleted in this directory, and commands such as touch and mv can be executed
x means that the file can be executed x means that you can enter the directory and execute the cd command

Let’s take a look below Command chmod, through which the permissions of files can be modified. First introduce the numerical representation of permissions: r (4), w (2), x (1)

# chown -R root:root study_file/ # chmod 700 study_file/ #数字方法设置权限 # ll -d study_file/ drwx------ 2 root root 4096 5月 5 13:13 study_file/ # chmod u=rwx,g=r,o=r 1.txt # chmod a-x 1.txt # chmod 600 *.txt # ll 总用量 4 -rw------- 1 root root 34 5月 5 12:22 1.txt -rw------- 1 root root 0 5月 5 13:13 2.txt -rw------- 1 root root 0 5月 5 13:13 3.txt
Copy after login

The above is the detailed content of Interpretation of file permissions under Linux system - (user, group, read, write and execute). For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
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
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!