Ubuntu Change folder and subfolder permissions

Source: Internet
Author: User
Tags chmod file permissions

How to modify the permissions of documents and folders (including subfolders) under Linux system, let's take a look. One introduction:

You can use the command chmod to grant permissions to a file or directory. Linux/unix's file access rights are divided into three levels: file owners, groups, and others. The use of chmod can be used to control how files are accessed by other two applications:

to want everyone to have read and write and Execute permissions, first open the terminal into the directory you need to modify,
Then execute the following command to change all subdirectories and file permissions to 777

To view Linux file permissions: Ls-l file name
To view Linux folder permissions: Ls-ld folder name (in directory)
To modify file and folder permissions:
sudo chmod-(representing type) xxx (owner) xxx (group user) xxx (other user)
commands for modifying permissions frequently:
sudo chmod 600xxx (only the owner has read and write permissions)
sudo chmod 644xxx (owner has read and write permission, group user only Read permission)
sudo chmod 700xxx (only the owner has read and write and permissions to execute)
sudo chmod 666xxx (everyone has read and write permissions)
sudo chmod 777xxx (everyone has read and write and Execute permissions) Three details 1 This command has two ways to use, one is chmod after the number, followed by the filename

Each of these a,b,c is a number, representing the permissions of user, Group, and other respectively.
R=4,w=2,x=1
To rwx the property is 4+2+1=7;
To rw-the property is 4+2=6;
To r-x the property is 4+1=5.
————————-Example ——————————— –
chmod a=rwx File
And
chmod 777 File
Same effect
chmod ug=rwx,o=x File
And
chmod 771 File
Same effect
If you use chmod 4755 filename, you can make this program have root permission 2 The other is chmod with the letter, followed by the filename

To sum up, when you want to use the chmod command to change permissions, the file's user identity is mainly the following categories:

U: the user (owner) who owns the file;

G: The group where the owner is located;

O: Other people (not owners or owners of the group);

A: Everyone or all (U, G, and O).

The types of file access permissions that users have are as follows:

R: Read right;

W: Write Right;

X: Executive power.

File permission configuration behavior has the following categories:

+: Add permissions;

-: Delete permissions;

=: Make it a unique permission.

—————————————————— Example —————————————————

Use the chmod command to change permissions. The following example shows how to use the chmod command to change the permissions of a Readme.txt file.

Suppose the following is the initial permission setting for the Readme.txt file:

-rw-rw-r–1 Winda Winda 39 August 12:04 Readme.txt

If you are the owner of this file, or if you are logged on as the root user, you can change the permissions of the owner, group, and other people. Initially, as can be seen from the analysis above, the owner and group of the Readme.txt file can read and write to the file (rw-), and anyone outside the group can read only the file (r –).

File permissions are a security measure. Whenever someone else is allowed to read, write, or execute a file, the risk of tampering or deletion of the file is increased. As a basic principle, only those who really need these documents should be given permission to read and write.

In the following example, you want to give everyone the right to write Readme.txt files, so they can read the file, raise it in it, and save the file. This means that you must change the "other people" section of the file permissions.

At this point you need to enter at the shell or terminal prompt:

chmod o+w Readme.txt

The o+w command parameter tells the system that you want to write the file Readme.txt permissions to others. To view the results, list the details of the file again. At this point, the user access rights for this file are shown below (a W in column 3rd):

-rw-rw-rw-1 Winda Winda 39 March 12:04 Readme.txt

Now, everyone can read and write to this file.

To remove a group and other people's read and write permissions from Readme.txt, use the chmod command to suppress both read and write permissions.

The order is as follows:

chmod GO-RW Readme.txt

Tells the system to delete the read and write permissions for the group and other people in the file Readme.txt by entering the GO-RW parameter. The results listed again through the LS-1 command are as follows:

-RW ——-1 Winda winda 39 March 12:04 Readme.txt

The commands for removing all permissions (including everyone's permissions) from file Readme.txt are as follows:

chmod a-rwx Readme.txt

Now, let's see if you can also use the Cat Readme.txt command to read this file, and the output it returns should look like this:

Cat:readme.txt:Permission denied

Delete all permissions, including your own, that will successfully lock the file. However, because this file belongs to the user, you can always use the following command to change its permissions back. The order is as follows:

chmod U+RW Readme.txt

Use the command cat Readme.txt to try whether or not to read the file as the owner of the file.

Here are a few common examples you can use on chmod command settings:

G+w: Add write rights to the Group;

O-RWX: Delete All other people's permissions;

U+x: Allow file owners to execute this file;

A+RW: Allows everyone to read and write files;

Ug+r: Allows owners and groups to read files;

G=RX: Only allow the group to read and execute (cannot write).

Finally, the method of recovering the permissions of the group is described. The order is as follows:

chmod ug+x Tigger

Now, if you check with the LS-DL command, you will find that only someone else (others) has been denied access to the directory Tigger.

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.