The management of multiple users in the Linux operating system is very cumbersome, so it becomes simple to manage users using the concept of groups. Each user can be in an independent group, and each group can have zero or multiple users. This article introduces the detailed explanation of the permission management commands in Linux (chmod/chown/chgrp/unmask). The specific contents are as follows: chmodexplain
grammar chmod [{ugoa}{+-=}{rwx}] [file or directory] chmod [mode=421] [file or directory] -R recursive modification # The first modification method chmod [{ugoa}{+-=}{rwx}] [file or directory] ugoa: u: Owner g: Group o: Others a: Everyone +-=: +: Add a permission to a file or directory -: Reduce a permission to a file or directory =: Give a file or directory new permissions, based on the current permissions # The second modification method chmod [mode=421] [file or directory] rwx: r:4 w:2 x:1 rwxrw-r-- Permission: 764 (4+2+1=7/4+2=6/4) Example# The first way to increase permissions chmod g+x test.txt [root@izm5e2q95pbpe1hh0kkwoiz tmp]# ls -l test.txt -rw-r--r-- 1 root root 11 Nov 28 15:39 test.txt [root@izm5e2q95pbpe1hh0kkwoiz tmp]# chmod g+x test.txt [root@izm5e2q95pbpe1hh0kkwoiz tmp]# ls -l test.txt -rw-r-xr-- 1 root root 11 Nov 28 15:39 test.txt # The second way to increase permissions: chmod 777 test.txt [root@izm5e2q95pbpe1hh0kkwoiz tmp]# ls -l test.txt -rw-r-xr-- 1 root root 11 Nov 28 15:39 test.txt [root@izm5e2q95pbpe1hh0kkwoiz tmp]# chmod 777 test.txt [root@izm5e2q95pbpe1hh0kkwoiz tmp]# ls -l test.txt -rwxrwxrwx 1 root root 11 Nov 28 15:39 test.txt Special attention to permissions# Create a new folder test under /tmp [root@izm5e2q95pbpe1hh0kkwoiz tmp]# mkdir test # Create a new test.txt in the /tmp/test folder [root@izm5e2q95pbpe1hh0kkwoiz tmp]# touch test/test.txt # View the files under the test file [root@izm5e2q95pbpe1hh0kkwoiz tmp]# ls -l test total 0 -rw-r--r-- 1 root root 0 Nov 28 17:54 test.txt # Check the permissions of the /tmp/test folder [root@izm5e2q95pbpe1hh0kkwoiz tmp]# ls -ld test drwxr-xr-x 2 root root 4096 Nov 28 17:54 test # Grant full permissions to the /tmp/test folder [root@izm5e2q95pbpe1hh0kkwoiz tmp]# chmod 777 test [root@izm5e2q95pbpe1hh0kkwoiz tmp]# ls -ld test drwxrwxrwx 2 root root 4096 Nov 28 17:54 test [root@izm5e2q95pbpe1hh0kkwoiz tmp]# ls -l test/test.txt -rw-r--r-- 1 root root 0 Nov 28 17:54 test/test.txt # Add a new ordinary user and change the password [root@izm5e2q95pbpe1hh0kkwoiz tmp]# useradd eternity [root@izm5e2q95pbpe1hh0kkwoiz tmp]# passwd eternity # Use the eternity account and password 123456 to log in to the server # View the current directory [eternity@izm5e2q95pbpe1hh0kkwoiz ~]$ pwd /home/eternity # Enter the /tmp directory [eternity@izm5e2q95pbpe1hh0kkwoiz ~]$ cd /tmp # Check the permissions of the /tmp/test directory, which has all permissions [eternity@izm5e2q95pbpe1hh0kkwoiz tmp]$ ls -ld test drwxrwxrwx 2 root root 4096 Nov 28 17:54 test # test.txt exists in the /tmp/test directory and has read permission [eternity@izm5e2q95pbpe1hh0kkwoiz tmp]$ ls -l test/test.txt -rw-r--r-- 1 root root 0 Nov 28 17:54 test/test.txt # Delete the test.txt file under /tmp/test [eternity@izm5e2q95pbpe1hh0kkwoiz tmp]$ rm test/test.txt rm: remove write-protected regular empty file 'test/test.txt'? y # Deletion is successful. At this time, test.txt no longer exists in the /tmp/test directory [eternity@izm5e2q95pbpe1hh0kkwoiz tmp]$ ls -l test/test.txt ls: cannot access test/test.txt: No such file or directory Only the administrator has rw read and write permissions, and the group and others have only read permissions. However, at this time, ordinary users deleted the file with only r read permissions. Why???? Summary of file directory permissions
analyze
chownexplain
grammar
In Linux, only root can change the file owner, not even the creator. Example # Change the file owner (change the owner of test.txt from eternity to root) chown root /tmp/test/test.txt [root@izm5e2q95pbpe1hh0kkwoiz ~]# pwd /root [root@izm5e2q95pbpe1hh0kkwoiz ~]# ls -l /tmp/test/test.txt -rw-r--r-- 1 eternity eternity 7 Nov 28 18:15 /tmp/test/test.txt [root@izm5e2q95pbpe1hh0kkwoiz ~]# chown root /tmp/test/test.txt [root@izm5e2q95pbpe1hh0kkwoiz ~]# ls -l /tmp/test/test.txt -rw-r--r-- 1 root eternity 7 Nov 28 18:15 /tmp/test/test.txt chgrpexplain Command name: chgrp The original meaning of the command in English: change file group ownership Command path:/bin/chgrp Execution permission: All users Function description: Change the group to which a file or directory belongs grammar
Example # Change the group to which the file belongs (change the group to which test.txt belongs from eternity to eternityz) chgrp eternityz /tmp/test/test.txt # Current directory [root@izm5e2q95pbpe1hh0kkwoiz ~]# pwd /root # View detailed information [root@izm5e2q95pbpe1hh0kkwoiz ~]# ls -l /tmp/test/test.txt -rw-r--r-- 1 root eternity 7 Nov 28 18:15 /tmp/test/test.txt # Add eternityz group [root@izm5e2q95pbpe1hh0kkwoiz ~]# groupadd eternityz # Change the group [root@izm5e2q95pbpe1hh0kkwoiz ~]# chgrp eternityz /tmp/test/test.txt [root@izm5e2q95pbpe1hh0kkwoiz ~]# ls -l /tmp/test/test.txt -rw-r--r-- 1 root eternityz 7 Nov 28 18:15 /tmp/test/test.txt umaskexplain
grammar
Example # View the default permissions of the file umask -S # Check umask umask [root@izm5e2q95pbpe1hh0kkwoiz ~]# umask 0022 0022 in 0 Special permissions 022 ----w--w- # Perform an XOR operation on all permissions 777 and 022 to get the default permission 777 rwx rwx rwx 022 --- -w- -w- ================ Directory rwx rx rx File rwx r-- r-- # Change the umask value to change the default permission umask 077 # After changing the umask value, the default permissions become 777 rwx rwx rwx 077 --- rwx rwx ================ Directory rwx --- --- File rw- --- --- # The following experiment complies with the setting of changing the default permissions [root@izm5e2q95pbpe1hh0kkwoiz ~]# umask 077 [root@izm5e2q95pbpe1hh0kkwoiz ~]# mkdir /tmp/lyf [root@izm5e2q95pbpe1hh0kkwoiz ~]# ls -ld /tmp/lyf drwx------ 2 root root 4096 Nov 29 10:55 /tmp/lyf [root@izm5e2q95pbpe1hh0kkwoiz ~]# touch /tmp/lyf/lyf [root@izm5e2q95pbpe1hh0kkwoiz ~]# ls -l /tmp/lyf/lyf -rw------ 1 root root 0 Nov 29 10:56 /tmp/lyf/lyf In Linux, only root can change the file owner. Even the creator cannot set the file creator as the default owner. In this case, the default group is also the file creator. The default permissions for folders in Linux are rwxr-xr-x, and the default permissions for files are rw-r--r--. New files do not have executable permissions. This is the end of this article about the detailed explanation of permission management commands in Linux (chmod/chown/chgrp/unmask). For more relevant Linux permission management command content, please search 123WORDPRESS.COM's previous articles or continue to browse the following related articles. I hope everyone will support 123WORDPRESS.COM in the future! You may also be interested in:
|
<<: Vue Router loads different components according to background data
>>: Solution to MySQL server login error ERROR 1820 (HY000)
Preface When a Linux is fully set up, you can use...
Table of contents Congruent and Incongruent congr...
Original address: https://blog.csdn.net/m0_465798...
Table of contents 1. Installation Environment 2. ...
Table of contents 1. Download the tomcat code 2. ...
The JavaScript hasOwnProperty() method is the pro...
Project scenario: There is a <ul> tag on th...
Table of contents SQL execution order bin log Wha...
Connection query: It is the result of connecting ...
MySQL Users and Privileges In MySQL, there is a d...
Here is a common one-click performance test scrip...
Preface Recently, I was analyzing the startup pro...
1. pc-reset PC style initialization /* normalize....
For Windows User Using openGauss in Docker Pull t...
Table of contents Preface Introduction Live Easy ...