What is the concept of linux permissions

PHPz
Release: 2023-05-18 11:40:13
forward
972 people have browsed it

chmod command detailed explanation

Usage permissions: All users

Usage method: chmod [-cfvR] [--help] [ --version] mode file...

         

  Linux/Unix file access permissions are divided into three levels: file owner, group, other . Use chmod to control how files are accessed by others.

Mode: Permission setting string, the format is as follows: [ugoa...][[ -=][rwxX]...][,...], where u represents the owner of the file , g represents those who belong to the same group as the owner of the file, o represents other people, and a represents all three.

means adding permissions, - means canceling permissions, = means setting only permissions.

r means readable, w means writable, x means executable, and X means only when the file is a subdirectory or the file has been set to be executable.

-c: If the file permissions have indeed been changed, the change action will be displayed.

-f: If the file permissions cannot be changed, do not display the error message

-v: Display detailed information about permission changes

-R: Make the same permission changes to all files and subdirectories in the current directory (that is, change them one by one in a recursive manner)

--help: Display auxiliary instructions

--version: Display version

Example:

Change file file1. txt is set to be readable by everyone

chmod ugo r file1.txt

Set file file1.txt is readable by everyone

chmod a r file1.txt

Set the files file1.txt and file2.txt to the owner of the file. People who belong to the same group can write to it, but other people can write to it. Then it cannot be written

chmod ug w,o-w file1.txt file2.txt

Set ex1.py so that only the owner of the file can execute

chmod u x ex1.py

Set all files and subdirectories in the current directory to be readable by anyone

chmod -R a r *

In addition, chmod can also use numbers to represent permissions, such as chmod 777 file

The syntax is: chmod abc file

Where a ,b,c are each a number, representing the permissions of User, Group, and Other respectively.

r=4, w=2, x=1

If you want rwx attribute, then 4 2 1=7;

If you want rw- attribute, then 4 2=6 ;

 If you want r-x attribute, then 4 1=7.

Example:

chmod a=rwx file has the same effect as chmod 777 file

chmod ug=rwx,o=x file and chmod 771 file The effect is the same

rootPermissions

Detailed explanation of chown command

Usage permissions:root

Usage: chown [-cfhvR] [--help] [--version] user[:group] file...

Description:

 Linux/Unix is ​​a multi-person, multi-tasking operating system, and all files have owners. Use chown The file owner can be changed. Generally speaking, this command can only be used by the system administrator (root). Generally, users do not have the permission to change other people's file owners, nor do they have the permission to change the file owner themselves. Change the owner of your file to someone else. Only the system administrator (root) has such permissions.

user: The user of the new file owner

IDgroup: The user group (group) of the new file owner

-c: If the Only display the change action if the file owner has indeed been changed

-f: Do not display an error message if the file owner cannot be changed

-h: Only change the link, not the file that the link actually points to

-v: Display the details of the owner change

-R: For the current All files and subdirectories in the directory undergo the same owner change (i.e., one by one in a recursive manner)

--help: Display auxiliary instructions

--version: Display version

Example:

Set the owner of the file file1.txt to the user jessie of the users group

chown jessie: users file1.txt

Set the owners of all files and subdirectories in the current directory to users of the users group lamport

chown -R lamport:users *

-rw------- (600) -- Only the owner has read and write permissions.

-rw-r--r-- (644) -- Only the owner has read and write permissions; group users and other users only have read permissions.

-rwx------ (700) -- Only the owner has read, write, and execute permissions.

-rwxr-xr-x (755) -- The owner has read, write, and execute permissions; while group users and other users only have read and execute permissions.

-rwx--x--x (711) -- The owner has read, write, and execute permissions; while group users and other users only have execution permissions.

-rw-rw-rw- (666) -- All users have file read and write permissions. This approach is not advisable.

-rwxrwxrwx (777) -- All users have read, write, and execute permissions. An even more undesirable approach.

The following are two common settings for the directory:

drwx------ (700) - Only the owner can read and write in the directory .

drwxr-xr-x (755) - All users can read the directory, but only the owner can change the contents of the directory

The representative number of suid is 4, such as 4755 The result of sgid is -rwsr-xr-x

The representative number of sgid is 2, for example, the result of 6755 is -rwsr-sr-x

The representative number of sticky bit is 1, for example, the result of 7755 is - rwsr-sr-t

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

Related labels:
source:yisu.com
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
Popular Tutorials
More>
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!