人妖在线一区,国产日韩欧美一区二区综合在线,国产啪精品视频网站免费,欧美内射深插日本少妇

新聞動(dòng)態(tài)

linux中權(quán)限管理命令詳解(chmod/chown/chgrp/unmask)

發(fā)布日期:2022-02-09 15:46 | 文章來(lái)源:gibhub

Linux操作系統(tǒng)對(duì)多用戶的管理,是非常繁瑣的,所以用組的概念來(lái)管理用戶就變得簡(jiǎn)單,每個(gè)用戶可以在一個(gè)獨(dú)立的組,每個(gè)組也可以有零個(gè)用戶或者多個(gè)用戶。本文給大家介紹linux中權(quán)限管理命令詳解(chmod/chown/chgrp/unmask),具體內(nèi)容如下:

chmod

解釋

命令名稱:chmod 命令英文原意:change the permissions mode of a file 命令所在路徑:/bin/chmod 執(zhí)行權(quán)限:所有用戶功能描述:改變文件或目錄權(quán)限

語(yǔ)法

chmod [{ugoa}{+-=}{rwx}] [文件或目錄](méi) 
chmod [mode=421] [文件或目錄](méi)
 -R 遞歸修改
 
# 第一種修改方式 chmod [{ugoa}{+-=}{rwx}] [文件或目錄](méi)
ugoa:
 u:所有者
 g:所屬組
 o:其他人
 a:所有人
+-=:
 +:針對(duì)文件或目錄增加某個(gè)權(quán)限
 -:針對(duì)文件或目錄減少某個(gè)權(quán)限
 =:賦予文件或目錄全新的權(quán)限,以此刻的權(quán)限為準(zhǔn)
 
# 第二種修改方式 chmod [mode=421] [文件或目錄](méi)
rwx:
 r:4
 w:2
 x:1
rwxrw-r--
 權(quán)限:764(4+2+1=7/4+2=6/4)

示例

# 第一種增加權(quán)限
 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
# 第二種增加權(quán)限
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

權(quán)限特別注意

# 在/tmp下新建文件夾test
[root@izm5e2q95pbpe1hh0kkwoiz tmp]# mkdir test
# 在/tmp/test文件夾下新建test.txt
[root@izm5e2q95pbpe1hh0kkwoiz tmp]# touch test/test.txt
# 查看test文件下的文件
[root@izm5e2q95pbpe1hh0kkwoiz tmp]# ls -l test
total 0
-rw-r--r-- 1 root root 0 Nov 28 17:54 test.txt
# 查看/tmp/test文件夾的權(quán)限
[root@izm5e2q95pbpe1hh0kkwoiz tmp]# ls -ld test
drwxr-xr-x 2 root root 4096 Nov 28 17:54 test
# 賦予/tmp/test文件夾全部的權(quán)限
[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
# 新增加一個(gè)普通用戶并修改密碼
[root@izm5e2q95pbpe1hh0kkwoiz tmp]# useradd eternity
[root@izm5e2q95pbpe1hh0kkwoiz tmp]# passwd eternity
# 使用eternity帳號(hào),密碼123456,登錄服務(wù)器
# 查看當(dāng)前目錄
[eternity@izm5e2q95pbpe1hh0kkwoiz ~]$ pwd
/home/eternity
# 進(jìn)入/tmp目錄
[eternity@izm5e2q95pbpe1hh0kkwoiz ~]$ cd /tmp
# 查看/tmp/test目錄的權(quán)限,擁有全部權(quán)限
[eternity@izm5e2q95pbpe1hh0kkwoiz tmp]$ ls -ld test
drwxrwxrwx 2 root root 4096 Nov 28 17:54 test
# /tmp/test目錄下存在test.txt,擁有讀權(quán)限
[eternity@izm5e2q95pbpe1hh0kkwoiz tmp]$ ls -l test/test.txt
-rw-r--r-- 1 root root 0 Nov 28 17:54 test/test.txt
# 刪除/tmp/test下的test.txt文件
[eternity@izm5e2q95pbpe1hh0kkwoiz tmp]$ rm test/test.txt
rm: remove write-protected regular empty file ‘test/test.txt'? y
# 刪除成功,此時(shí)/tmp/test目錄下test.txt已經(jīng)沒(méi)有了
[eternity@izm5e2q95pbpe1hh0kkwoiz tmp]$ ls -l test/test.txt
ls: cannot access test/test.txt: No such file or directory

只有管理員擁有rw讀寫權(quán)限,所屬組和其他人只有讀權(quán)限,但是此時(shí)普通用戶卻刪除了只有r讀權(quán)限的文件,為什么???? 文件目錄權(quán)限總結(jié)

代表字符 權(quán)限 對(duì)文件的含義 對(duì)目錄的含義
r 讀權(quán)限 可以查看文件內(nèi)容 可以列出目錄中的內(nèi)容
w 寫權(quán)限 可以修改文件內(nèi)容 可以在目錄中創(chuàng)建和刪除文件
x 執(zhí)行權(quán)限 可以執(zhí)行文件 可以進(jìn)入目錄

分析

對(duì)于文件有寫權(quán)限,僅僅代表可以修改文件的內(nèi)容,而沒(méi)有刪除文件的權(quán)限

對(duì)于目錄有寫權(quán)限,可以在目錄中創(chuàng)建和刪除文件

因?yàn)樯厦娴?tmp/test目錄的權(quán)限為777 所以普通用戶對(duì)于/tmp/test目錄也具有創(chuàng)建文件和刪除文件的權(quán)限所以,普通用戶也能刪除/tmp/test/test.txt文件但是普通用戶無(wú)法編輯/tmp/test/test.txt文件,使用vim編輯文件的時(shí)候,會(huì)提示W(wǎng)aring: Changing a readonly file

chown

解釋

命令名稱:chown 命令英文原意:change file ownership 命令所在路徑:/bin/chown 執(zhí)行權(quán)限:所有用戶功能描述:改變文件或目錄的所有者

語(yǔ)法

chown [用戶] [文件或目錄](méi)

在linux中只有root能改變文件所有者,即便是創(chuàng)建者都不可以

示例

# 改變文件所有者(將test.txt的所有者由eternity更改為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

chgrp

解釋

命令名稱:chgrp
命令英文原意:change file group ownership
命令所在路徑:/bin/chgrp
執(zhí)行權(quán)限:所有用戶
功能描述:改變文件或目錄的所屬組

語(yǔ)法

chgrp [用戶組] [文件或目錄](méi)

示例

# 改變文件所屬組(將test.txt的所屬組由eternity更改為eternityz)
chgrp eternityz /tmp/test/test.txt
# 當(dāng)前目錄
[root@izm5e2q95pbpe1hh0kkwoiz ~]# pwd
/root
# 查看詳細(xì)信息
[root@izm5e2q95pbpe1hh0kkwoiz ~]# ls -l /tmp/test/test.txt
-rw-r--r-- 1 root eternity 7 Nov 28 18:15 /tmp/test/test.txt
# 增加eternityz組
[root@izm5e2q95pbpe1hh0kkwoiz ~]# groupadd eternityz
# 改變所屬組
[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

umask

解釋

命令名稱:umask 命令英文原意the user file-creation mask 命令所在路徑:shell內(nèi)置命令執(zhí)行權(quán)限:所有用戶功能描述:顯示/設(shè)置文件的缺省權(quán)限

語(yǔ)法

umask [-S] -S 以rwx形式顯示新建文件缺省權(quán)限(大寫的S)

示例

# 查看文件的缺省權(quán)限
umask -S
# 查看umask
umask
[root@izm5e2q95pbpe1hh0kkwoiz ~]# umask
0022
0022中
0 特殊權(quán)限
022 ----w--w-
# 通過(guò)所有權(quán)限777和022權(quán)限進(jìn)行異或操作,得到缺省權(quán)限
777 rwx rwx rwx
022 --- -w- -w-
================
目錄 rwx r-x r-x
文件 rwx r-- r--

# 更改umask值,進(jìn)而改變?nèi)笔?quán)限
umask 077
# 更改umask值之后,缺省權(quán)限變?yōu)?777 rwx rwx rwx
077 --- rwx rwx
================
目錄 rwx --- ---
文件 rw- --- ---
# 以下實(shí)驗(yàn)符合更改缺省權(quán)限的設(shè)置
[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

在linux中只有root能改變文件所有者,即便是創(chuàng)建者都不可以文件的創(chuàng)建者為默認(rèn)的所有者,此時(shí)默認(rèn)的所屬組也是文件創(chuàng)建者 linux中文件夾的缺省權(quán)限時(shí)rwxr-xr-x,文件的缺省權(quán)限是rw-r--r--,新建文件不具備可執(zhí)行權(quán)限

到此這篇關(guān)于linux中權(quán)限管理命令詳解(chmod/chown/chgrp/unmask)的文章就介紹到這了,更多相關(guān)linux 權(quán)限管理命令內(nèi)容請(qǐng)搜索本站以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持本站!

國(guó)外服務(wù)器租用

版權(quán)聲明:本站文章來(lái)源標(biāo)注為YINGSOO的內(nèi)容版權(quán)均為本站所有,歡迎引用、轉(zhuǎn)載,請(qǐng)保持原文完整并注明來(lái)源及原文鏈接。禁止復(fù)制或仿造本網(wǎng)站,禁止在非www.sddonglingsh.com所屬的服務(wù)器上建立鏡像,否則將依法追究法律責(zé)任。本站部分內(nèi)容來(lái)源于網(wǎng)友推薦、互聯(lián)網(wǎng)收集整理而來(lái),僅供學(xué)習(xí)參考,不代表本站立場(chǎng),如有內(nèi)容涉嫌侵權(quán),請(qǐng)聯(lián)系alex-e#qq.com處理。

相關(guān)文章

實(shí)時(shí)開通

自選配置、實(shí)時(shí)開通

免備案

全球線路精選!

全天候客戶服務(wù)

7x24全年不間斷在線

專屬顧問(wèn)服務(wù)

1對(duì)1客戶咨詢顧問(wèn)

在線
客服

在線客服:7*24小時(shí)在線

客服
熱線

400-630-3752
7*24小時(shí)客服服務(wù)熱線

關(guān)注
微信

關(guān)注官方微信
頂部