日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 运维知识 > linux >内容正文

linux

Linux系统权限

發(fā)布時間:2025/6/17 linux 23 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Linux系统权限 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

第1章 Linux系統(tǒng)權(quán)限

1.1 簡介
Linux中的文件或目錄的權(quán)限和用戶及用戶組關(guān)聯(lián)很大,Linux中每個文件或目錄都有一組共9個基礎(chǔ)權(quán)限位,每三個字符被分為一組,他們分別是屬主權(quán)限位(占三個字符)、屬組權(quán)限位(占三個字符)、其他用戶權(quán)限位(占三個字符)。
比如rwxr-xr-x linux中正是這9個權(quán)限位來控制文件屬主(User)、屬組(Group)、其他用戶(Other)基礎(chǔ)權(quán)限。


1.2 三種角色
用戶對資源來說, 有三種角色
User(u): 屬主用戶(文件所有者)
Group(g): 屬組用戶(包含組成員)
Other(o): 匿名用戶(其他人)


1.3 環(huán)境

[root@oldboyedu ~]# ll -d dir drwxr-xr-x. 2 root root 18 8月 16 17:11 dir [root@oldboyedu ~]# ll -d dir/file -rw-r--r--. 1 root root 0 8月 16 17:11 dir/file

1.3.1 權(quán)限描述
/root/dir的權(quán)限是所屬用戶root讀寫執(zhí)行,所屬組root讀執(zhí)行,其他用戶讀執(zhí)行
/root/dir/file的權(quán)限是所屬用戶root讀寫,所屬組root讀,其他用戶讀


1.4 修改文件所屬命令 chown
修改文件所屬
chown [user][.|:][group] [-R] filename

//修改屬主
[root@oldboyedu ~]# chown oldboy /root/dir
[root@oldboyedu ~]# ll -d /root/dir


//修改屬組
[```
root@oldboyedu ~]# chown .dba /root/dir
[root@oldboyedu ~]# ll -d /root/dir
d-wx--x--x. 2 oldboy dba 29 8月 16 17:24 /root/dir


1.5 修改權(quán)限命令chmod


第一種方式: chmod [ugoa] [+-=] [rwx] [-R] filename // a是全部
[root@oldboyedu ~]# chmod u=rx /root/dir
[root@oldboyedu ~]# ll -d dir
dr-xr-xr-x. 2 root root 18 8月 16 17:11 dir
[root@oldboyedu ~]# chmod u+w /root/dir
[root@oldboyedu ~]# ll -d dir
drwxr-xr-x. 2 root root 18 8月 16 17:11 dir
[root@oldboyedu ~]# chmod u-w /root/dir
[root@oldboyedu ~]# ll -d dir
dr-xr-xr-x. 2 root root 18 8月 16 17:11 dir
[root@oldboyedu ~]# chmod a=rwx /root/dir
[root@oldboyedu ~]# ll -d dir
drwxrwxrwx. 2 root root 18 8月 16 17:11 dir
[root@oldboyedu ~]# chmod a= /root/dir
[root@oldboyedu ~]# ll -d dir
d---------. 2 root root 18 8月 16 17:11 dir
[root@oldboyedu ~]# chmod =rx /root/dir
[root@oldboyedu ~]# ll -d dir
dr-xr-xr-x. 2 root root 29 8月 16 17:24 dir


第二種方式: chmod nnn [-R] filename //nnn 表示U G O
所屬用戶rw,屬組用戶只讀,其他用戶沒權(quán)限
4+2=6 4 0
[root@oldboyedu ~]# chmod 640 /root/dir/file
[root@oldboyedu ~]# ll /root/dir/file
-rw-r-----. 1 root root 0 8月 16 17:11 /root/dir/file


1.6 遞歸修改目錄權(quán)限(修改目錄及子目錄權(quán)限)

chmod -R 權(quán)限 filename [root@oldboyedu ~]# ll -d /root/dir drwxr-xr--. 2 root root 29 8月 16 17:24 /root/dir [root@oldboyedu ~]# ll -d /root/dir/file -rw-r-----. 1 root root 0 8月 16 17:11 /root/dir/file [root@oldboyedu ~]# chmod -R 755 /root/dir [root@oldboyedu ~]# ll -d /root/dir/file -rwxr-xr-x. 1 root root 0 8月 16 17:11 /root/dir/file

第2章 文件權(quán)限實(shí)驗(yàn)案例


2.1 默認(rèn)文件其他用戶僅有讀權(quán)限

[root@oldboy ~]# echo "date" >/tmp/date.txt [root@oldboy ~]# ll /tmp/date.txt -rw-r--r--. 1 root root 5 Aug 16 06:37 /tmp/date.txt

2.2 測試讀權(quán)限(無法執(zhí)行或刪除)

[root@oldboy ~]# su - oldboy [oldboy@oldboy ~]$ cat /tmp/date.txt date [oldboy@oldboy ~]$ echo "test" >/tmp/date.txt -bash: /tmp/date.txt: Permission denied [oldboy@oldboy ~]$ /tmp/date.txt -bash: /tmp/date.txt: Permission denied

//增加x執(zhí)行權(quán)限
root@oldboy ~]# chmod o+x /tmp/date.txt
[root@oldboy ~]# ll /tmp/date.txt
-rw-r--r-x. 1 root root 5 Aug 16 06:37 /tmp/date.txt

//測試執(zhí)行權(quán)限**

[oldboy@oldboy ~]$ /tmp/date.txt
Thu Aug 16 06:40:56 CST 2018

//增加w寫權(quán)限

[root@oldboy ~]# chmod o+w /tmp/date.txt
[root@oldboy ~]# ll /tmp/date.txt
-rw-r--rwx 1 root root 5 Aug 16 06:38 /tmp/date.txt


//測試寫權(quán)限
[oldboy@oldboy ~]$ echo "test" >/tmp/date.txt
或者使用vim編輯文件來測試

第3章 rwx對文件的影響


3.1 讀取權(quán)限(r)
文件只有r權(quán)限: 具有讀取\閱讀文件內(nèi)容權(quán)限
1.能使用查看類命令 cat、head、tail、less、more
2.不能復(fù)制、不能移動、不能編輯,不能刪除


3.2 寫入權(quán)限(w)
如果文件只有w權(quán)限: 具有新增、修改文件內(nèi)容的權(quán)限
1.使用vim編輯,會提示權(quán)限拒絕, 但可強(qiáng)制保存,會覆蓋之前文件內(nèi)容
2.使用echo命令重定向或追加重定向技術(shù)可以往文件內(nèi)寫入數(shù)據(jù)
3.使用cat命令讀取文件, 將讀取到的文件輸出交給僅有w權(quán)限文件的輸入
4.不能復(fù)制、不能移動、不能刪除,(刪除需要看上級目錄w的權(quán)限)


3.3 執(zhí)行權(quán)限(x)
文件只有x權(quán)限,具有執(zhí)行文件的權(quán)限。
//注意: 普通用戶需要有r權(quán)限,管理員不需要
1.不能執(zhí)行、查看、編輯、復(fù)制、移動、刪除


第4章 目錄權(quán)限實(shí)驗(yàn)案例


4.1 實(shí)戰(zhàn)案例1: 對目錄沒有 w,對文件有 rwx

[root@oldboy ~]# mkdir /test [root@oldboy ~]# echo "test" > /test/test.txt [root@oldboy ~]# chmod 777 /test/test.txt [root@oldboy ~]# ll -d /test drwxr-xr-x. 2 root root 22 Aug 16 06:52 /test [root@oldboy ~]# ll /test/test.txt -rwxrwxrwx. 1 root root 5 Aug 16 06:52 /test/test.txt

普通用戶驗(yàn)證權(quán)限

[oldboy@oldboy ~]$ cat /test/test.txt test [oldboy@oldboy ~]$ rm -f /test/test.txt rm: cannot remove ‘/test/test.txt’: Permission denied

4.2 實(shí)戰(zhàn)案例2: 對目錄有 w,對文件沒有任何權(quán)限

[root@oldboy ~]# chmod 777 /test/ [root@oldboy ~]# chmod 000 /test/test.txt [root@oldboy ~]# ll -d /test drwxrwxrwx. 2 root root 22 Aug 16 06:52 /test [root@oldboy ~]# ll -d /test/test.txt ----------. 1 root root 5 Aug 16 06:52 /test/test.txt

//普通用戶驗(yàn)證權(quán)限
[oldboy@oldboy ~]$ cat /test/test.txt
cat: /test/test.txt: Permission denied
[oldboy@oldboy ~]$ rm -f /test/test.txt
[oldboy@oldboy ~]$ touch /test/test1.txt

4.3 實(shí)戰(zhàn)案例3: 對目錄沒有 x,對文件有任何權(quán)限

[root@oldboy ~]# chmod 766 /test/ [root@oldboy ~]# chmod 777 /test/test.txt [root@oldboy ~]# ll -d /test/ drwxrw-rw-. 2 root root 22 Aug 16 06:58 /test/ [root@oldboy ~]# ll /test/test.txt -rwxrwxrwx. 1 root root 5 Aug 16 06:58 /test/test.txt

//普通用戶驗(yàn)證權(quán)限
[oldboy@oldboy ~]$ cd /test
-bash: cd: /test: Permission denied
[oldboy@oldboy ~]$ cat /test/test.txt
cat: /test/test.txt: Permission denied
[oldboy@oldboy ~]$ rm -f /test/test.txt
rm: cannot remove ‘/test/test.txt’: Permission denied


第5章 rwx對目錄的影響


5.1 目錄只有r權(quán)限: 具有瀏覽目錄及子目錄權(quán)限
1.能使用ls命令瀏覽目錄及子目錄, 同時會提示權(quán)限拒絕
2.能使用ls -l命令瀏覽目錄及子目錄, 會帶問號,同時只能看到文件名
總結(jié): 目錄只有r權(quán)限,僅僅只能瀏覽內(nèi)的文件名,無其他操作權(quán)限


5.2 寫入權(quán)限(w)
如果目錄只有w權(quán)限:具有增加、刪除或修改目錄內(nèi)文件名權(quán)限(需要x配合)
//注意:如果目錄有w權(quán)限, 可以在目錄創(chuàng)建文件, 可以刪除目錄中的文件(跟文件權(quán)限無關(guān))
不能進(jìn)入目錄、不能復(fù)制目錄、不能刪除目錄、不能移動目錄


5.3 執(zhí)行權(quán)限(x)
目錄只有x權(quán)限
1.只能進(jìn)入目錄
2.不能瀏覽、復(fù)制、移動、刪除


5.4 權(quán)限小結(jié):
文件rw權(quán)限, 可以查看和編輯文件內(nèi)容
文件rx權(quán)限, 只能查看和執(zhí)行文件、不能編輯、復(fù)制、移動、刪除
目錄rx權(quán)限, 允許瀏覽目錄內(nèi)文件以及子目錄、并允許在目錄內(nèi)新建文件, 不允許創(chuàng)建、刪除文件和目錄


> 注意事項(xiàng):

文件, x權(quán)限小心給予,建議賦予r或rw即可
目錄, w權(quán)限小心給予,建議無特殊需求賦予rx即可

轉(zhuǎn)載于:https://blog.51cto.com/13904281/2173705

總結(jié)

以上是生活随笔為你收集整理的Linux系统权限的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。