Modify folder permissions in Linux

Source: Internet
Author: User
In Linux, the CHMOD/chgrp/chown folder permission is set to 1777. This number indicates that all users can create files in this directory, but only the file owner can delete the files.

First, let's take a look at the file attributes,In the shell environment, enter LS-L to view the current directory file. For example:
Drwxr-XR-x 2 NSF users 1024 12-10 download file backup
They correspond:
File Attribute connection count file owner group file size file modification time file name
Here, R is readable, W is writable, and X is executable. The file attributes are divided into four sections and ----10 positions.
For example:
D rwx R-x r-x
The first character specifies the file type. In general, a directory is also a file. If the first character is a horizontal line, it indicates a non-directory file. If it is D, it indicates a directory.
The second part is the permissions of the file owner,
The third section is the permissions of the group to which the file belongs,
The fourth section is the permissions for other users,
For example, the "download file backup" access permission in the preceding folder indicates that the "download file backup" folder is a directory file; the owner of the "download file backup" folder has the read and write permissions; users in the same group as the folder "download file backup" have only the read and executable permissions. Other users also have the read and executable permissions.

After determining the access permission for a file, you can use the CHMOD command provided by Linux to reset different access permissions. You can also use the CHOWN command to change the owner of a file or directory. Use the chgrp command to change the user group of a file or directory.

Chmod command
Function: the CHMOD command is very important for changing the access permissions of files or directories. You can use it to control the access permissions of files or directories.
Syntax: This command can be used in two ways. One is the text setting method that contains letters and operator expressions, and the other is the number setting method that contains numbers.
1. text setting method
Chmod [who] [+ |-| =] [mode] File Name?
Parameters:
The operator who is one of the following letters or their combination:
U indicates "user", that is, the owner of a file or directory.
G indicates "group users", that is, all users with the same group ID as the file owner.
O indicates "Other (Others) Users ".
A Indicates "All (all) Users ". It is the default value of the system.
The operation symbol can be:
+ Add a permission.
-Cancel a permission.

= Grant the given permission and cancel all other permissions (if any ).

Set the permissions indicated by mode to any combination of the following letters:
R readable.
W writable.
X executable.
X adds the X attribute only when the target file is executable to some users or the target file is a directory.
S sets the owner or group ID of the process to the file owner during file execution. In the format of "U + s", set the user ID bit of the file, and "G + S" to set the group ID bit.
T save the program text to the swap device.
U has the same permissions as the file owner.
G. users in the same group have the same permissions as file owners.
O has the same permissions as other users.
File Name: list of files separated by spaces to change permissions. Wildcards are supported.
Multiple permission methods can be provided in a command line, separated by commas. Example: chmod g + R, O + r example
Grant the same group and other users the permission to read the file example.

2. Number setting method

In addition, there is a way to modify the number.
Rwx corresponds to 4 2 1 3 digits (remember that binary and 10 hexadecimal conversion should be quite memorable ),
Then, corresponding to a user, 1 indicates that only -- X, 3 indicates-WX, 5 indicates R-X, and so on, that is, the sum of the numbers of each permission indicates
A combination of permissions. Run the following command:
Chmod 777 bbb
That is, all permissions of each user in BBB are added.
Chmod 751 bbb
Sets the current user to all permissions. the user group has only the RX permission, and other users have only the X permission.

Chgrp command
Function: Change the group to which a file or directory belongs.
Syntax: chgrp [Option] group filename?
This command changes the user group to which the specified file belongs. The Group can be either the user group ID or the group name of the user group in the/etc/group file. A file name is a list of files separated by spaces to change the group. Wildcards are supported. If the user is not the owner or super user of the file, the file group cannot be changed.
Parameters:
-R recursively changes the group of all subdirectories and files in a specified directory.
Example 1: $ chgrp-r book/opt/local/book
Change the owner group of all files in/opt/local/book/and its subdirectories to book.

CHOWN command
Function: Modify the owner and group of a file or directory. This command is also very common. For example, if the root user copies a file to Xu, the root user should set the owner of the file to Xu to allow Xu to access the file. Otherwise, user Xu cannot access this file.
Syntax: chown [Option] user or group file
Note: chown will change the owner of a specified file to a specified user or group. Users can be user names or user IDs. A group can be a group name or group ID. Files are separated by spaces to change the permission list. Wildcards are supported.
Parameters:
-R recursively changes the owner of all subdirectories and files under a specified directory.
-V: displays the work done by the CHOWN command.
Example 1: Change the owner of the Shiyan. c file to Wang.
$ Chown Wang Shiyan. c

Example 2: Change the group of files/home and all files and subdirectories to users.
$ Chown-R. Users/home

Example 3: Change the owner of the directory/his and all files and subdirectories to Wang and the group to users.
$ Chown-r Wang. Users/his

 

Chmod o + rwx/root

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.