How Linux Changes file properties and permissions

Source: Internet
Author: User

How Linux Changes file properties and permissions

We know that file permissions for a system of security importance, but also know the permissions of the file for users and groups of relevance, then how to modify the properties and permissions of a file?

Here we introduce several directives that are commonly used for groups, owners, and various identities. As shown below:

CHGRP: Change the group that the file belongs to

Chown: Changing the file owner

chmod: Features that change file permissions, SUID, SGID, Sbit, and so on

1. Change the group you belong to, CHGRP


Options and Parameters:
-R: Continuous change of recursion (recursive), that is, all files and directories under the sub-directory are updated to the meaning of this group. Often used to change the status of all files in a directory.
Example:


08:

Chgrp:invalid group name ' testing' <== error message ~ Can't find this group name ~

2. Change the file owner, Chown

[Email protected] ~]# Chown [-R] Account name file or directory [[email protected] ~]# Chown [-R: Continuous change of recursion (recursive), That is, together with all the files in the sub-directory, change the example: Change the owner of the Install.log to bin this account: [[email protected] ~]# Chown Bin Install.log [[email protected] ~]# ls-l 
-rw-r--r--1 bin users 68495 June 25 08:53< Span style= "color: #000000;" > Install.log Example: Change the owner and group of Install.log back to root: [[email protected] ~]# chown Root: Root Install.log [[email protected] ~]# ls-l
-rw-r--r--1 root root 68495 June 25 08:53 Install.log

3. Change permissions, chmod

There are two ways to set permissions, and you can use numbers or symbols to change permissions.

3.1 Number types Change file permissions

There are nine basic permissions on the Linux file, each of which has its own Read/write/execute authority, owner/group/others three different identities.

Example: The file's permission character is-rwxrwxrwx this nine permission is three three a group! Where we can use numbers to represent individual permissions, the scores for each permission are as follows:

R:4 W:2 x:1

Each identity (Owner/group/others) 's respective three permission (R/W/X) scores are cumulative, such as when the permission is: [-rwxrwx---] score:

Owner = rwx = 4+2+1 = 7

Group = RWX = 4+2+1 = 7

others=---= 0+0+0 = 0

So when we set a change in permissions, the number of permissions on that file is 770! The syntax for the Change permission directive chmod is this:

[[email protected] ~]# chmod [-R] xyz file or directory options and parameters: XYZ: Is the permission property of the number type just mentioned, which adds the value of the rwx attribute. -R: Continuous change of recursion (recursive), i.e. all files in the sub-directory will be changed

For example, if you want to set the. bashrc file with all permissions enabled, then release:


11:


One:BASHRC.

What if you want to turn permissions into-rwxr-xr--? Then the score of the privilege becomes [4+2+1][4+0+1][4+0+0]=754! So you need to release:

[Email protected] ~]# chmod 754 filename

3.2 Symbol Type change file permissions

There is also a way to change the permissions yo! From the previous introduction, we can find that basically nine permissions are (1) User (2) group (3) Others three kinds of identities! Then we can represent three kinds of identities by u, G, O! In addition, a represents all and all identity! Then the permission to read and write can be written as R, W, X! That is, you can see it in the following way:

Let's experiment! If we want to set a file's permission to become "-rwxr-xr-x", basically is:
o User (U): With readable, writable, executable permissions;
O Group and Others (G/O): Has the ability to read and not execute.

So it is:




One:BASHRC.

So what if it's a privilege like "-rwxr-xr--"? You can use "chmod u=rwx,g=rx,o=r filename" to set it. Also, if we know the original file attributes, and I just want to increase the. BASHRC per-person writable permissions for this file, then I can use:


11:


One:BASHRC.

And if you want to remove permissions without changing other existing permissions? For example, to take out the executable permissions of all people:



One:BASHRC.

How Linux Changes file properties and permissions

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.