Linux diary Day3---Linux file attributes and directory configuration

Source: Internet
Author: User
Tags comparison table readable

One of the best places in Linux is its multi-user, multitasking environment . In order to make the user have a more secure management mechanism, the file Rights management is very important. Linux generally divides the way files are accessed into three categories, namely Owner/group/other, and has permissions such as Read/write/excute. What does it mean to have so many directories/files under Linux? Let's take a brief introduction.

First, user and user group

1. File owner (user)

Because Linux is a multi-user, multitasking system that may often be used by multiple people at the same time, it is important for the owner to take into account the privacy of everyone and the work environment everyone prefers. For example , when you dump an e-mail message into a file and put it under your own home folder, this time, set the file to " only the file owner to view and modify the contents of this file ." Even if others know that you own the file, they cannot know the contents of the file because the file has the appropriate permissions set.

2. User groups

user groups (group ) are the aggregate of users with the same characteristics , For example , sometimes we want to have multiple users with the same permissions , such as viewing, Modify a file or execute a command, we need the user group, we define the user to the same user group, we modify the permissions of the file or directory, so that the user group has a certain operational rights , so that users under the user group has the same permissions to the file or directory , which we do by defining the group and Modifying the permissions of the file .

let's start by stating: The file owner has nothing to do with the user group itself , such as the user group can be root, but the file owner is user1;

Case Analysis:

(1) The file owner of a file is User1, the user group is root, the current logged on user is User1,

If you want to make the owner of the file root, can it be successful? cannot ;

(2) The file owner of a file is User1, the user group is root, the current login user is root,

If you want to make the owner of the file root, can it be successful? can ;

Summary point : Change the file owner, user group should be the root user 's responsibility ;

One more point: a user will always belong to one or more user groups, a user group can have multiple users, such as root users belong to the root user group, but we can also create a user User1, belong to the group1 user group, Also belong to the group2 user group;

3. The Others

In Linux, any file has three permissions for users, groups of users, and others. We can explain it in Figure 1.1来. At this point, in the figure of Wang Sanmao as an example, Wang Sanmao This "file" owner is Wang Sanmao , it belongs to Wang Damao This user group , and Zhang Piggy relative to Wang Sanmao , is just one other person .

Figure 1.1

Explanation: Root is the Super Administrator user account in Linux and UNIX systems, which has the supremacy of the entire system and can operate on all objects.

Second, Linux file permissions

1. Linux file properties

Open terminal, execute LS command, query file information 2.1 shown

Figure 2.1

Note: Themeaning of "connection" : Refers to the occupied node (I-node is the I node), The new directory contains ". and." Two directories, with a connection of 2 and a new subdirectory, increase the number of connections in turn, but the added files do not increase the number of connections.

2. Linux File Permission Properties

Example : If you have a file with a property of "-rwxr-xr-", note that the following numbers represent the first few, and do not represent permission encodings.

The description is as follows: [-] [R W x] [r-x] [R--]

1 2 3 4 5 6 7 8 9 0

1: indicates that the file name is a directory or file (above is a file ).

234: The owner 's permissions ( readable , writable, executable ).

567: user Rights with user groups (above is readable , executable ).

890: Other user rights (above are readable only ).

<1> The above attributes indicate a file, the owner of the file is readable , writable, and executable . But the person with the user group can only read and execute . users who are not in the same user group only readable meaning .

<2> in addition, it is important to note that x. If the file name is a directory , the relationship between x and the directory is very important, if you can not execute any command in this directory , then nature will not be able to enter, therefore, please pay special attention, if you want to open a directory to let some people come in , Keep in mind that the x property of the directory is open . For a description of the permissions for the directory, we'll continue with the following.

3. Change file permissions

3.1 file Permissions Three musketeers:chgrp , chown , chmod

· chgrp Change to group :chgrp [-R] group name dir/file(-R recursive subdirectory all files, directories are updated to this group ):

Assign dir or file to the group name

· Chown Change owner : chown [Options] users [. Groups] File/dir :

Option:-v Displays the work of the Chown command .

- R Ibid, period available ":" instead

· chmod Change Permissions : chmod [-R] nnn file or directory

Note: When theshell file is edited with VI , the permissions change and the permissions need to be changed.

3.2 How permissions are modified

File attributes are changed using the chmod command, but there are two ways to set the property, either a number or a symbol, respectively.

<1> Number types change file permissions

There are 9 basic properties of Linux files, namely owner/Group/Others, group read/write/ Excute Properties, first review the data just mentioned above:

–RWX rwx rwx

These 9 properties are in groups of three. Where you can use numbers to represent individual attributes, the comparison table for each property is as follows:

Authority representative Number : r→4; w→2; x→1

The 3 attributes (r/w/x) of the same group (owner/group/others) are cumulative, for example , when the property is [- RWXRWX---] is:

owner = rwx = 4+2+1 = 7

Group = rwx = 4+2+1 = 7

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

So, wait a minute. When you set a property change, the number of the property is 770.

The syntax for changing a property's command chmod is this:

[[email protected] ~]# chmod [-r] XYZ file or directory

Parameters:

XYZ: is the permission attribute of the number type just mentioned, which is the sum of the numeric values of the Rwx property.

-R: A continuous change of recursion (recursive), that is, all files and directories under subdirectories are updated to this user group. Often used in situations where a directory is changed.

Linux diary Day3---Linux file attributes and directory configuration

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.