日韩无码专区无码一级三级片|91人人爱网站中日韩无码电影|厨房大战丰满熟妇|AV高清无码在线免费观看|另类AV日韩少妇熟女|中文日本大黄一级黄色片|色情在线视频免费|亚洲成人特黄a片|黄片wwwav色图欧美|欧亚乱色一区二区三区

RELATEED CONSULTING
相關(guān)咨詢
選擇下列產(chǎn)品馬上在線溝通
服務(wù)時間:8:30-17:00
你可能遇到了下面的問題
關(guān)閉右側(cè)工具欄

新聞中心

這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
linux中權(quán)限管理命令詳解(chmod/chown/chgrp/unmask)
umask

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

創(chuàng)新互聯(lián)是一家集網(wǎng)站建設(shè)、網(wǎng)站設(shè)計、網(wǎng)站頁面設(shè)計、網(wǎng)站優(yōu)化SEO優(yōu)化為一體的專業(yè)網(wǎng)站建設(shè)公司,已為成都等多地近百家企業(yè)提供網(wǎng)站建設(shè)服務(wù)。追求良好的瀏覽體驗,以探求精品塑造與理念升華,設(shè)計最適合用戶的網(wǎng)站頁面。 合作只是第一步,服務(wù)才是根本,我們始終堅持講誠信,負(fù)責(zé)任的原則,為您進行細(xì)心、貼心、認(rèn)真的服務(wù),與眾多客戶在蓬勃發(fā)展的市場環(huán)境中,互促共生。

chmod

解釋

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

語法

chmod [{ugoa}{+-=}{rwx}] [文件或目錄]
chmod [mode=421] [文件或目錄]
-R 遞歸修改

# 第一種修改方式 chmod [{ugoa}{+-=}{rwx}] [文件或目錄]
ugoa:
u:所有者
g:所屬組
o:其他人
a:所有人
+-=:
+:針對文件或目錄增加某個權(quán)限
-:針對文件或目錄減少某個權(quán)限
=:賦予文件或目錄全新的權(quán)限,以此刻的權(quán)限為準(zhǔn)

# 第二種修改方式 chmod [mode=421] [文件或目錄]
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

# 新增加一個普通用戶并修改密碼
[root@izm5e2q95pbpe1hh0kkwoiz tmp]# useradd eternity
[root@izm5e2q95pbpe1hh0kkwoiz tmp]# passwd eternity

# 使用eternity帳號,密碼123456,登錄服務(wù)器
# 查看當(dāng)前目錄
[eternity@izm5e2q95pbpe1hh0kkwoiz ~]$ pwd
/home/eternity

# 進入/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

# 刪除成功,此時/tmp/test目錄下test.txt已經(jīng)沒有了
[eternity@izm5e2q95pbpe1hh0kkwoiz tmp]$ ls -l test/test.txt
ls: cannot access test/test.txt: No such file or directory

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

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

分析

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

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

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

chown

解釋

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

語法

chown [用戶] [文件或目錄]

在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)限:所有用戶
功能描述:改變文件或目錄的所屬組

語法

chgrp [用戶組] [文件或目錄]

示例

# 改變文件所屬組(將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)限

語法

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

示例

# 查看文件的缺省權(quán)限
umask -S

# 查看umask
umask

[root@izm5e2q95pbpe1hh0kkwoiz ~]# umask
0022

0022中
0 特殊權(quán)限
022 —-w–w-

# 通過所有權(quán)限777和022權(quán)限進行異或操作,得到缺省權(quán)限
777 rwx rwx rwx
022 — -w- -w-
================
目錄 rwx r-x r-x
文件 rwx r– r–

# 更改umask值,進而改變?nèi)笔?quán)限
umask 077

# 更改umask值之后,缺省權(quán)限變?yōu)?br /> 777 rwx rwx rwx
077 — rwx rwx
================
目錄 rwx — —
文件 rw- — —

# 以下實驗符合更改缺省權(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)的所有者,此時默認(rèn)的所屬組也是文件創(chuàng)建者 linux中文件夾的缺省權(quán)限時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)容請搜索以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持!

成都創(chuàng)新互聯(lián)科技有限公司,是一家專注于互聯(lián)網(wǎng)、IDC服務(wù)、應(yīng)用軟件開發(fā)、網(wǎng)站建設(shè)推廣的公司,為客戶提供互聯(lián)網(wǎng)基礎(chǔ)服務(wù)!
創(chuàng)新互聯(lián)(www.cdcxhl.com)提供簡單好用,價格厚道的香港/美國云服務(wù)器和獨立服務(wù)器。創(chuàng)新互聯(lián)成都老牌IDC服務(wù)商,專注四川成都IDC機房服務(wù)器托管/機柜租用。為您精選優(yōu)質(zhì)idc數(shù)據(jù)中心機房租用、服務(wù)器托管、機柜租賃、大帶寬租用,可選線路電信、移動、聯(lián)通等。


文章標(biāo)題:linux中權(quán)限管理命令詳解(chmod/chown/chgrp/unmask)
當(dāng)前地址:http://m.5511xx.com/article/dhpdggs.html