Linux privilege management command

Disclaimer: This article is a blogger original article, shall not be reproduced without the bloggers allowed. https://blog.csdn.net/young2415/article/details/89219201

Change the file permissions

Name command: chmod

Command English original intent: change the permissions mode of a file

There are two roles can execute the command, one is the root user, the other is the owner of the file.

grammar:

chmod [{ugoa} {+-=} {rwx}] [文件或目录]
	  [mode=42] [文件或目录]
	  -R 递归修改

Braces contents represent only choose one, which indicates that the owner of the file u, g represents the owning group, o represents other people, a representation of all the roles.

For example, belongs to the group abc.txt file a written permission to add:

chmod g+w abc.txt

You can also be done simultaneously multiple licenses, such as file owner to add execute permission to others to remove write permissions:

chmod u+x,o-w abc.txt

Permissions can also be expressed numerically. Digital Rights, said:

r ---- 4

w ---- 2

x ---- 1

If a file permissions are rw-r-r--, then translated into numbers is 644, in turn, if you want to change the file permissions, you can write:

chmod 644 abc.txt

Such permission would file into the rw-r -----.

There is an option -R recursively modify the permissions, the function of this option is to change the permissions for all subdirectories and files in the directory at the same time to change a directory permissions.

chmod -R 644 tmp

Change the file's owner

Command name: chown

English original intent: change owner

Syntax: chown username file

Only an administrator account can change your user files.

E.g:

chown supermouse abc.txt #将abc.txt文件的所有者改成supermouse

Change the file belongs to the group of

Command name: chgrp

English original intent: change group

Syntax: chgrp group file name

E.g:

chgrp staff abc.txt #将abc.txt文件的所属组改成staff

View and change the default file permissions

Command name: umask

Use the command umask -Scan view the default permissions for new files or directories.

[root@localhost ~]# umask -S
u=rwx,g=rx,o=rx

Now displays the default permissions for the new directory, the default permissions for the owner of the directory is rwx, belongs to the group of default permissions are rx, default permissions for other people is rx. Why is this default permissions are the default permissions for the new directory instead of the new file, if you have permission to view the new file, you will find that rw-r--r--, with the new directory permissions rwxr-xr-xcompared to the permissions each role are less x. So, just know that the default permissions for the new directory, and then remove the x permission, is the new default file permissions.

If direct execution umask command displays a number.

[root@localhost ~]# umask
0022

This number is called permission mask, followed by three 777 minus 022 to get permission for each role, ie 755. It is translated into letters rwxr-xr-x.

If you want to change the new default directory or file permissions, simply execute umask 权限掩码can be.

For example, I want to change the default permissions of the new directory rwxr-r--, translated into numbers is 744, then 777 minus 744 to get permission mask 033.

umask 033 #将默认权限改成rwxr--r--

Although the default permissions to the directory or file can modify the Linux system, but Linux distribution rights This is a grain of truth, it is best not easily modified.

Guess you like

Origin blog.csdn.net/young2415/article/details/89219201