A document that reads Linux's content (attributes, owners, groups, permissions)

We all know that Linux is a system that supports multi-user and multi-tasking. This is also its best feature. That is, there may be many people working on the system at the same time, so do not force shutdown, and at the same time, in order to protect everyone Privacy and work environment, for a certain document (files, directories), the Linux system defines three kinds of identities, namely, owner, group, and others, and each identity corresponds to three. Permissions are readable, writable, and excutable.

Document properties

Use the command ls -al --full-time, or the shorthand ll of this command to view all the attributes of a file or directory. as follows:

A document that reads Linux's content (attributes, owners, groups, permissions)

As you can see from the above, each row has 7 columns, which are:

The first column contains 10 digits. The first digit indicates the document type, d indicates the directory, - indicates the file, l indicates the linked file, d indicates a randomly accessible device, such as a U disk, and c indicates a one-time reading device. Mouse, keyboard, etc. The last nine digits, in turn, correspond to the rights owned by the three types of identities. The identity sequence is: owner, group, others, and the permission sequence is: readable, writable, and excutable. Such as: -r-xr-x --- the meaning of the current document is a file, the owner is readable, executable, the same group under the user, readable, writable, others do not have any authority.

The second column shows the number of links

The third column shows the owner

The fourth column shows the group

The fifth column shows the size of the document, in bytes

The sixth column indicates the last modification time of the document. Note that it is not the creation time of the document.

The seventh column shows the document name. Starting with a dot (.) is hidden document

Change owner

position

Etc/passwd

A document that reads Linux's content (attributes, owners, groups, permissions)

Note: It must be an existing account in this location. That is, the owner of the record in /etc/passwd can change.

grammar

Chown[-R][account name][file or directory]

Chown[-R][account name]:[group name][file or directory]

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

Options

-R recursively changes, that is, all files (folders) along with the subdirectory must be changed.

usage

Chown daemon test Change the folder test account to daemon.

A document that reads Linux's content (attributes, owners, groups, permissions)

Chown daemon:root test Change the folder test group to root.

Chown root.users test Change the folder account to root and the group to users

A document that reads Linux's content (attributes, owners, groups, permissions)

Chown .root test Change group as root

Note: Although it is also possible to add a decimal point (.) between the owner and the group, it is advisable to use a colon ":" to separate the owner from the group to avoid misidentification.

Change group

position

Etc/group

Note: All groups can be viewed from here

grammar

Chgrp [-options] [group name] [document path]

Remarks: For options, detailed usage can be queried by commands such as man chgrp, info chgrp, and chgrp --help.

usage

Chgrp -R users test Change the group of the test folder and all its subfolders (folders) to users.

Note: If the group name is not in the location, an invalid group will be reported.

A document that reads Linux's content (attributes, owners, groups, permissions)

Change permissions

There are three basic permissions for Linux documentation, read/write/execute, plus only nine identity owners/group/others. There are two ways to change the permissions, which are the symbol method and the numerical method.

- Symbol method

Respectively use u, g, o to represent three kinds of identities, a means all identities; use r, w, and x respectively to represent three types of permissions; use +, -, and = for operation behaviors.

grammar

Chmod | ugoa | + (join) - (remove) = (set) | rwx | document path

Set permissions (=)

Change the permissions of the directory test for anyone to read, write, and execute.

Chmodu=rwx,g=rwx,o=rwx test

or

Chmod ugo=rwx test

or

Chmoda=rwx test

A document that reads Linux's content (attributes, owners, groups, permissions)

Remove permissions (-)

Remove the directory test execution permissions

Chmodu-x,gx,o-xtest

or

Chmod ugo-xtest

or

Chmoda-xtest

A document that reads Linux's content (attributes, owners, groups, permissions)

Remarks: Execute permission (x), for the directory is just whether other users can cd test to become a working directory.

Add permissions (+)

Increase the directory test execute permission

Chmodu+x,g+x,o+xtest

or

Chmod ugo+xtest

or

Chmoda+xtest

A document that reads Linux's content (attributes, owners, groups, permissions)

Remarks: very familiar with it, if we write a shell file test.sh after the chmod a + x test.sh to add the file execute permissions.

- Number method

As the name suggests, it is the use of numbers to represent permissions, r, w, and x are 4, 2, and 1, respectively. Accumulation of three kinds of permissions can give you an identity.

Set the permissions of the directory test to be readable, writable and executable by anyone.

Chmod 777 test

A document that reads Linux's content (attributes, owners, groups, permissions)

Set the permissions of the directory test to be readable and writable by anyone.

Chmod 666 test

A document that reads Linux's content (attributes, owners, groups, permissions)

Give a shell file test.sh executable rights, owner readable, write, execute, group accounts and others readable and executable.

Chmod 755 test

Remarks: Is it easier to find the number method? ! !

File and directory permissions differences

Document permissions have a huge difference for files and directories

file

For the content of this file

Readable can read the actual contents of the file

Writable can edit, add or modify the contents of the file

Executable has permission to 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.

table of Contents

For the file object in this directory

Readable has the permission to read the directory structure list, that is, you can query the directory list by the ls command.

Writable has permission to change the directory structure list, that is, you can create, migrate, delete, and rename the files in the directory.

Executable has permission to enter the directory, that is, you can use the cd command to go to the working directory.

Remarks: From the above it can be concluded that, when browsing an open directory to anyone, at least r or x rights must be granted. To read the content of the directory file, at least directory permission x and file permission r are required.

to sum up

Each document of Linux can give rwx permission to three kinds of identity respectively; chgrp command changes the file group, chmod command changes the file permissions, chown changes the file owner; then remember to use the document permissions to protect the security of the data.

Forward Centrifugal Fan

Forward Centrifugal Fan,Backward Inclined Airfoil Fans,Backward Curved Blade Centrifugal Fans,Backward Curved Blade Fan

Hangzhou Jinjiu Electric Appliance Co Ltd. , https://www.jinjiufanmotor.com

This entry was posted in on