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

How to change file and directory permissions by Linux

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

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

This article mainly explains the "Linux how to change file and directory permissions", the article explains the content is simple and clear, easy to learn and understand, the following please follow the editor's ideas slowly in depth, together to study and learn "Linux how to change file and directory permissions" bar!

1. Quick example learning:

Modify the permissions of all files in a directory, including files in subdirectories, as shown in the following example:

# chmod 777 / home/user Note: only set the permissions of the / home/user directory to rwxrwxrwx# chmod-R 777 / home/user Note: it means that the permissions of the entire / home/user directory and its files and subdirectories are set to rwxrwxrwx

Parameter-R indicates that recursive processing is started

2. Chmod command parsing:

Chmod uses three numbers to express permissions to users (owners of files or directories), user groups (users in the same group), and other users:

For example, chmod 777 / test

The number 7 is an expression with read, write, and execute permissions: read-- represented by the number 4

Write-represented by the number 2

Execute-denoted by the number 1

According to the rules, if you want to set the permissions of the / test directory to:

Readable and writable to users: 4 (read) + 2 (write) = 6

Readable and executable to user groups: 4 (read) + 1 (execute) = 5

Readable only to other users: 4 (read)

This allows you to use the command:

Chmod 654 / test

3. Permission resolution:

Three permissions for files:

Read the contents of the file (r), write the data to the file (w), and act as the command execution file (x)

Three permissions for directories:

Read the file name contained in the directory (r)

Write information to the directory (add and delete links to index points, w)

Search for a directory (you can use this directory name as a path name to access the files and subdirectories it contains)

Specific description:

Users with read-only access cannot enter the directory using cd: you must also have execute permission to enter

Users with execute permission can access the files in the directory only if they know the file name and have the right to read.

You must have read and execute permissions to ls to list directories, or to enter directories using the cd command

With write access to a directory, you can create, delete, or modify any file or subdirectory in a directory, even if it belongs to another user

Several examples of common permissions:

-rw- (600) only the owner has read and write permission

-rw-r--r-- (644) only the owner has read and write access, and groups and others only have read permission

-rwx- (700) only the owner has the permission to read, write and execute

-rwxr-xr-x (755) only the owner has read, write, and execute permissions, and groups and others only have read and execute permissions

-rwx--x--x (711) only the owner has the permission to read, write, and execute, and groups and others only have the permission to execute

-rw-rw-rw- (666) everyone has read and write access

-rwxrwxrwx (777) everyone has access to read, write and execute

4. Special permissions:

There are three kinds of special permissions:-- s--s--t

Owner s permission: a special permission called Set UID, or SUID for short; that is, when the file is executed, it will have the permissions of the file owner.

Group s permissions: special permissions called Set GID or SGID for short; that is, the directories and files established under this directory belong to a fixed group.

The final t permission, called Sticky Bit, or SBIT permission for short, is valid only for directories. It means that only the owner and root can delete (rename / move) files in this directory.

Special permissions are granted and revoked:

1. Set UID

# chmod Umurs home/usr01/test# chmod Umurs home/usr01/test

2. Set GID

# chmod Grips home/usr01/test# chmod Gmurs home/usr01/test

3. Sticky Bit

# chmod Omurt home/usr01/test# chmod Omurt home/usr01/test

Or:

# chmod 0755 home/usr01/test

The 0755 first 0 indicates that no special permissions are used, and the number on this bit can be:

0 (- -); 1 (--t); 2 (- s -); 3 (- st); 4 (smurt -); 5 (smurt); 6 (ss-); 7 (sst)

The system specifies that if there is an x in that bit, these special flags (suid, sgid, sticky) are displayed as lowercase letters (s, s, t). Otherwise, it appears in uppercase letters (S, S, T).

In addition: chmod 777 abc

Chmod + t abc

Equivalent to

Chmod 1777 abc

Thank you for your reading, the above is the content of "how Linux changes file and directory permissions". After the study of this article, I believe you have a deeper understanding of how Linux changes file and directory permissions, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!

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

Database

Wechat

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

12
Report