In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/02 Report--
The management of multi-users in Linux operating system is very tedious, so it is easy to use the concept of group to manage users. Each user can be in an independent group, and each group can have zero or more users. This article introduces the detailed description of privilege management commands (chmod/chown/chgrp/unmask) in linux. The details are as follows:
Chmod
explain
Command name: chmod command English meaning: change the permissions mode of a file command path: / bin/chmod execution authority: all user function description: change file or directory permissions
Grammar
Chmod [{ugoa} {+-=} {rwx}] [file or directory] chmod [mode=421] [file or directory]-R recursive modification # first modification method chmod [{ugoa} {+-=} {rwx}] [file or directory] ugoa: U: owner g: group o: others a: everyone +-=: +: add some permission to the file or directory -: for the text Reduce a permission by a piece or directory =: give a file or directory a new permission The second way of modification is chmod [mode=421] [file or directory] rwx: RGV 4wJV 2xRV 1rwxrw Murray-permission: 764 (4x 2pm 7pm 7pm 4) example # the first way to add permissions chmod glossy test.txt [root@izm5e2q95pbpe1hh0kkwoiz tmp] # ls-l test.txt-rw-r--r-- 1 root root 11 Nov 28 test.txt [root@izm5e2q95pbpe1hh0kkwoiz tmp] # chmod glossx test.txt [ Root@izm5e2q95pbpe1hh0kkwoiz tmp] # ls-l test.txt-rw-r-xr-- 1 root root 11 Nov 28 15:39 test.txt# second additional 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 permissions Pay special attention to # create a new folder under / tmp test [root@izm5e2q95pbpe1hh0kkwoiz tmp] # mkdir test# create a new test.txt [root@izm5e2q95pbpe1hh0kkwoiz tmp] # touch test/test.txt# under the / tmp/test folder to view files under the test file [root@izm5e2q95pbpe1hh0kkwoiz tmp] # ls-l testtotal 0RwMuk RUV-1 root root 0 Nov 28 17:54 test.txt# View / tmp/test folder permissions [root@izm5e2q95pbpe1hh0kkwoiz tmp] # ls -ld testdrwxr-xr-x 2 root root 4096 Nov 28 17:54 test# gives full permissions to / tmp/test folder [root@izm5e2q95pbpe1hh0kkwoiz tmp] # chmod 777 test [root@izm5e2q95pbpe1hh0kkwoiz tmp] # ls-ld testdrwxrwxrwx 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# uses eternity account Password 123456, login server # View current directory [eternity@izm5e2q95pbpe1hh0kkwoiz ~] $pwd/home/eternity# enter / tmp directory [eternity@izm5e2q95pbpe1hh0kkwoiz ~] $cd / tmp# view / tmp/test directory permissions, have full permissions [eternity@izm5e2q95pbpe1hh0kkwoiz tmp] $ls-ld testdrwxrwxrwx 2 root root 4096 Nov 28 17:54 test# / tmp/test directory exists test.txt 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.txtrm: remove write-protected regular empty file 'test/test.txt'? Y# deleted successfully, the test.txt in the / tmp/test directory is no longer [eternity@izm5e2q95pbpe1hh0kkwoiz tmp] $ls-l test/test.txtls: cannot access test/test.txt: No such file or directory
Only the administrator has read and write access to rw, and his group and others only have read access, but at this time, ordinary users delete files with only r read permission. Why? Summary of file directory permissions
Represents the meaning of the character permission to the meaning of the file to the meaning of the directory r read permission can view the contents of the file can list the contents of the directory w write permissions can modify the contents of the file can create and delete files in the directory x execute permissions can execute files can enter the directory analysis
Write permission for a file, which only means that the contents of the file can be modified, but there is no permission to delete the file.
You have write access to the directory, and you can create and delete files in the directory
Because the above / tmp/test directory has 777 permissions, ordinary users also have permission to create and delete files in the / tmp/test directory, so ordinary users can also delete / tmp/test/test.txt files, but ordinary users cannot edit / tmp/test/test.txt files. When editing files using vim, they will prompt Waring: Changing a readonly file.
Chown
explain
Command name: chown command English meaning: change file ownership command path: / bin/chown execution authority: all user function description: change the owner of the file or directory
Grammar
Chown [user] [file or directory]
In linux, only root can change the owner of the file, not even the creator
Example
# change the owner of the file (change the owner of the 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.txtchgrp
explain
Command name: chgrp command English meaning: change file group ownership command path: / bin/chgrp execution authority: all user function description: change the group to which the file or directory belongs
Grammar
Chgrp [user group] [file or directory]
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 details [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.txtumask
explain
Command name: umask command English original meaning the user file-creation mask command path: shell built-in command execution rights: all user function description: display / set default permissions for files
Grammar
Umask [- S]-S displays the default permissions for new files in rwx form (uppercase S)
Example
# View the default permissions of files umask-S# View umaskumask [root @ izm5e2q95pbpe1hh0kkwoiz ~] # umask00220022 0 special permissions 022-w--w-# with all permissions 777 and 022 permissions XOR operations, get the default permissions 777 rwx rwx rwx022-Wantha w-= directory rwx rmurx file rwx rmurm-r Muffe # change the umask value, and then change the default permission umask 07permission after changing the umask value The default permission is changed to 777 rwx rwx rwx077-rwx rwx= directory rwx- file rw- # the following experiments conform to the setting of changing the default permission [root@izm5e2q95pbpe1hh0kkwoiz ~] # umask 077 [root@izm5e2q95pbpe1hh0kkwoiz ~] # mkdir / tmp/lyf [root@izm5e2q95pbpe1hh0kkwoiz ~] # ls-ld / tmp/lyfdrwx- 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 owner of the file, even the creator cannot be the default owner of the file. At this time, the default ownership group is also rwxr-xr-x when the folder in the file creator linux has the default permission. The default permission of the file is that rw-r--r--, new file does not have executable permission.
So far, this is the end of this article on the detailed explanation of rights management commands (chmod/chown/chgrp/unmask) in linux. For more information about linux rights management commands, please search the previous articles or continue to browse the relevant articles below. I hope you will support me in the future!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.