Linux File Permission, Linux File Permission

Source: Internet
Author: User

Linux File Permission, Linux File Permission

To learn about this chapter, you must understand the following three concepts:

1. Owner

2. Group

3. Others

After understanding these three concepts, we will learn the attributes of the file. What are the attributes of the file? How can I view the attributes of a file?

Run ls-l in the command line.

You can get the following information (only one piece of information has been analyzed)

-Rw-r --. 1 root 41312 Dec 10 install. log
...

Explanation:
The first column indicates the file type and permissions.

The first character is "-", indicating that the file is a normal file.

The file types in Linux are as follows:

-: Common files, including file files and binary files
D: directory file
C: character Device File
B: block Device Files
S: socket File)
L: Link file
P: MPS queue file (FIFO, pipe)
There may be other file types, which can be supplemented later.

The next nine characters, three in a group, indicate the permissions of the owner, the group, and others.

Three r (read) read, w (write) write, and x (execute) are permitted.

The second column indicates how many file names are linked to this node (I-node), that is, the number of hard links to the file.

The third column indicates the owner of the file.

The fourth column indicates the group to which the file belongs.

The fifth column indicates the size of the file, in the unit of B.

The sixth column indicates the file creation date or the latest modification as scheduled.

Column 7 indicates the file name

Bytes ------------------------------------------------------------------------------------------

Change file attributes and permissions

The required Commands include:

Chgrp: Modify the group to which the file belongs.

Chown: Modify the file owner

Chmod: Modify file permissions

Introduction to changing the chgrp command of the user group

Use the following file as an example.

-Rw-r --. 1 root 41312 Dec 10 install. log

As mentioned above, the owner of the install. log file is root and the owner group is root. The permission is rw-r --

If you want to modify the group to which the file belongs, you can do this.

Assume that a group of super has been defined under/etc/group.

# Chgrp super install. log modify the group

# Ls-l

-Rw-r --. 1 root super 41312 Dec 10 install. log file is changed to super

---------------------------------------------------------------------------------

Change the file owner chown command

Assume that the user hello already exists in/etc/passwd.

If you want to modify the above install. log File owner, you can do this

# Chown hello install. log modify the file owner to hello

# Ls-l
-Rw-r --. 1 hello super 41312 Dec 10 install. log File owner is changed to hello

The chown command can also modify the group to which the object belongs.

For example, to change the file owner and group to the original root, you can do this.

# Chown root: root install. log

# Ls-l
-Rw-r --. 1 root 41312 Dec 10 install. log
The file owner and group have been modified.

The chown command can also modify only the group

# Chown: super install. log

# Ls-l

-Rw-r --. 1 root super 41312 Dec 10 install. log

In most cases, use the colon ":" to separate the owner and group, or use the decimal point.

Under what circumstances do I need to modify the owner or group of a file?

For example, we use the cp command to copy a file to another user's home directory, but the file property does not
Modify, that is, another user cannot operate the file even if the file is obtained. In this case, you need to modify the attributes of the file.

Bytes ------------------------------------------------------------------------------------

Run the chmod command to modify file permissions.

Use the above file as an example.

-Rw-r --. 1 root 41312 Dec 10 install. log

Analysis:
The file owner has rw permission on the file, that is, reading and writing, and cannot execute

The user of the file group has the r permission on the file, that is, only the read permission.

Others have the r permission on the file, that is, only the read permission.

There are two methods to modify the File Permission:

1. Modify the File Permission for the numeric type

R (4)
W (2)
X (1)

There can be so many Representation Methods
--- 0
-- X 1
-W-2
-Wx 3
R -- 4
R-x 5
Rw-6
Rwx 7


Command example
To change the object ACL
Rwx r-x
7 5

# Chmod 755 install. log
# Ls-l

The following result is displayed:
-Rwxr-xr-x. 1 root 41312 Dec 10 install. log

This method is not intuitive and requires conversion. individuals prefer to use the character type to modify file permissions.

Modify file permissions for character types

The command is as follows:

----------------------------------------------------------
U + (ADD) r
Chmod g-(remove) w files or directories
O = (SET) x
A

----------------------------------------------------------

U (user): indicates the owner

G (group): indicates the group

O (others): Indicates others

A (all): indicates the three

Example

-Rwxr-xr-x. 1 root 41312 Dec 10 install. log

If you want to modify the File Permission to rw-r-xr-x, that is, the owner does not have the execution (x) permission, you can do this.

# Chmod u-x install. log

To modify the File Permission to rw-rwxr-x, that is, add the write (w) permission to the group, you can do this.

# Chmod g + w install. log

If you want to modify the File Permission to rw-rwxrw-, that is, other people have the read/write (rw) permission, you can do this.

# Chmod o = rw install. log

To modify the File Permission to rwxrwxrwx, you can do this.

# Chmod a + x install. log

Of course, this can also be used.

# Chmod u-x, g-x, o-r install. log

I wonder if I have made it clear ..


---------------------------------------------------------------------------------

Directory and File Permissions

Importance of permissions on files

R (read): You can read the actual content of this file. For example, you can use commands such as cat to view the file content.

W (write): You can edit, add, or modify the file content, but cannot delete the file.

X (execute): The file has the permission to be executed by the system.

By the way, the extension. In LInux, there is no extension concept, which is different from that in windows. So is the file
It can be executed. It depends on permission x, but it must be clear that it can be executed. It does not mean it can be executed successfully,
This depends on the file content.

Summary: for files, rwx is mainly used for file content permissions, but it has an absolute relationship with the file name removal.


Importance of permissions on directories

R (read contents in directory)

Indicates that you have the permission to read the list of directory structures. That is to say, you can use ls to view the files in the directory.

W (modify contents of directory)

Indicates that you have the permission to change the directory structure list, that is, you can
1. Create a file or directory
2. delete an existing file or directory (regardless of the permission of the file)
3. Rename the file or directory
4. Transfer the files and directories in the directory

In short, the w permission of a directory is related to changes in the file name under the directory.

X (access directory)

Indicates whether the user can enter the directory to become a working directory.

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.