Detailed description of Linux document properties, owners, groups, permissions, differences

Source: Internet
Author: User
Tags chmod readable file permissions

Write in front

We all know that Linux is a multi-user, multi-tasking system, which is also its best feature, it is possible to have a lot of people working on the system, so do not force shutdown , at the same time, in order to protect everyone's privacy and work environment, For a document (file, directory), the Linux system defines three identities, namely owner (owner), Group (group), others (others), each identity and three kinds of permissions, respectively, is readable (readable), writable (writable), executable (excutable).

Document properties

ls -al --full-time ll You can view all the properties of a file or directory by using a command, or a shorthand for this command. As follows:

As you can see from above, each row has 7 columns, namely:

    1. First column
      A total of 10 bits, the 1th digit represents a document type, d represents a directory, represents a - file, represents a l linked file, represents d a device that can be randomly accessed, such as a USB flash drive, etc., c indicating a disposable read device, such as a mouse, keyboard, etc. After 9 bits, in turn corresponds to three kinds of identities have the rights, the identity order is: Owner, group, others, the order of permissions are: readable, writable, excutable. such as: -r-xr-x--- the meaning of the current document is a file, the owner can read, executable, the same group of users, readable, writable, other people do not have any permissions .
    2. Second column
      Indicates the number of links
    3. Third column
      Represents the owning person
    4. Fourth column
      Indicates the owning group
    5. Fifth Column
      Indicates the document capacity size, in bytes
    6. Sixth column
      Indicates when the document was last modified, not when the document was created.
    7. Seventh column
      Represents the document name. With Dot (.) The beginning is the hidden document
Change owner (owner) Location
etc/passwd

Note: You must be an account that already exists in this location. That is, the /etc/passwd owner of a record can change.

Grammar
chown [-R] [帐号名称] [文件或目录]chown [-R] [帐号名称]:[群组名称] [文件或目录]

Note: This command can also change the document group by the way, but it is recommended to use the chgrp command to change the document group.

Options

-R recursive change, that is, all files (folders) in the secondary directory must be changed.

Usage

chown daemon testChange Folder Test account is daemon.

chown daemon:root testChange Folder Test group to root.

chown root.users testChange Folder account is root, group is users

chown .root testChange group as root individually

Note: Although you can also add a decimal point between the owner and the group (.), but in order to avoid some students named in the DOT, it is recommended to use the colon ":" to separate owners and groups, to avoid miscalculation.

Change group Location
etc/group

Note: All groups can be viewed from here

Grammar
chgrp [-options] [群组名] [文档路径]

Note: For options, you can man chgrp、info chgrp、chgrp --help query for detailed usage by waiting for commands.

Usage

chgrp -R users testtestthe group that changes the folder and all its sub-files (folders) is users .

Note: The group name is not in the location, will be an error invalid group .

Change permissions

Linux documents have three basic permissions, respectively read/write/execute , plus owner/group/others nine identities. There are 2 ways to change permissions, namely, symbolic and digital .

Symbolic method

Using U,g,o to represent three identities, a for all identities, three permissions using R, W, x respectively, using + 、-、 = for operation behavior, respectively

Grammar
Set Permissions (=)

The permission to change the catalog test is readable, writable, and executed by anyone.

chmod u=rwx,g=rwx,o=rwx test 或chmod ugo=rwx test 或chmod a=rwx test

Remove Permissions (-)

Remove directory test Execution permissions

chmod u-x,g-x,o-x test 或chmod ugo-x test 或chmod a-x test

Note: Execute permissions (x), the directory is just another user can CD test become working directory.

Add permissions (+)

Add directory Test Execution permissions

chmod u+x,g+x,o+x test 或chmod ugo+x test 或chmod a+x test

Note: It is very familiar, if we have finished writing a shell file test.sh, we have chmod a+x test.sh added file execution permissions.

Digital method

As the name implies, is the use of numbers to represent permissions, R,w,x, respectively, 4,2,1. Three kinds of permissions accumulate to obtain an identity permission.

The permissions to set the directory test are readable, writable, and executed by anyone.


The permission to set the directory test is readable and writable by anyone.

Give a shell file test.sh executable permissions, the owner can read, write, execute, group accounts and other people can read and execute.

Note: There is no way to find the digital method is more simple AH!!!

File and Directory Permissions differences

Document permissions are significantly different for files and directories

File

For the contents of the file

    • Readable can read the actual contents of the file
    • Writable can edit, add, or modify the contents of the file
    • Executable has permissions that can be executed by the system

Note: With W permissions can not delete files, delete files is the scope of directory permissions Control!!! Remember that file permissions are for file content .

Directory

For the file object in this directory

    • Readable has the permission to read the directory structure manifest, that is, the ls command can be used to query the directory list.
    • Writable has the ability to change the directory structure manifest to create, migrate, delete, and rename files in that directory.
    • Executable has permission to enter the directory, which can be transferred to the working directory via the CD command.

Note: From the above can be obtained, open Directory for anyone to browse, at least need to give r or x permission. Read the contents of the directory file, requiring at least directory permissions x and file permissions r .

Summarize

LinuxEach document can be assigned permissions for three identities, change file rwx chgrp groups, command change file chmod permissions, chown change file owner, then remember to use the document permissions to protect the security of the data Oh .

Detailed description of Linux document properties, owners, groups, permissions, differences

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.