Linux云计算【第一阶段】第四章:权限管理
第四章:權限管理
linux的文件管理權限分為讀、寫和執行
[root@localhost ~]# ls -l /bin/bash -rwxr-xr-x. 1 root root 960392 8月 3 2016 /bin/bash一.權限基本概念
1.權限對象
屬主: u
屬組: g
其他人: o
基本權限類型:
讀: r 4
寫: w 2
執行: x 1
-rwxr-xr-x.
2.共分為五個部分
-:表示文件類型
rwx:用戶屬主的權限
r-x:用戶屬組的權限
r-x:其他用戶的權限
.:是否啟用facl
3.權限對文件的作用
r:可獲取文件的數據;
w:可修改文件的數據;
x:可將此文件運行為進程;
4.權限對目錄的作用
r:可使用ls命令獲取其下的所有文件列表;
w:可修改此目錄下的文件列表;即創建或刪除文件,包括子目錄。
x:可cd至此目錄中;且可使用ls -l來獲取所有文件的詳細屬性信息
5.權限組合
二.設置權限
1.更改文件的屬主、屬組 //chown , chgrp命令[root@lxw ~]# chown alice.hr file1 //改屬主、屬組 [root@lxw ~]# chown alice file1 //只改屬主 [root@lxw ~]# chown .hr file1 //只改屬組 [root@lxw ~]# chown -R zhouchen.hr dir1 //同時改變該目錄及目錄下的所有文件和目錄所有者和所屬組 //-R 等于替歸[root@lxw ~]# chgrp it file1 //改文件屬組 [root@lxw ~]# chgrp -R it dir1 //改文件屬組 2.更改權限[root@lxw ~]# chmod u+x file1 //屬主增加執行 [root@lxw ~]# chmod a=rwx file1 //所有人等于讀寫執行 [root@lxw ~]# chmod a=- file1 //所有人沒有權限 [root@lxw ~]# chmod ug=rw,o=r file1 //屬主屬組等于讀寫,其他人只讀 [root@lxw ~]# ll file1 //以長模式方式查看文件權限 -rw-rw-r-- 1 alice it 17 10-25 16:45 file1 //顯示的結果[root@tianyun ~]# chmod 644 file1 //權限644為 rw-r--r-- [root@tianyun ~]# ll file1 -rw-r--r-- 1 alice it 17 10-25 16:45 file113.權限案例UGO [root@lxw ~]# groupadd hr //創建用戶組 [root@lxw ~]# useradd hr01 -G hr //指定用戶hr01至hr組 [root@lxw ~]# useradd hr02 -G hr //指定用戶hr02至hr組 [root@lxw ~]# mkdir /home/hr //創建/home/下的hr目錄[root@lxw ~]# chgrp hr /home/hr (chown .hr /home/hr) [root@lxw ~]# chmod 770 /home/hr //給予hr目錄rwxrwx---權限 [root@lxw ~]# ll -d /home/hr/ //以長格式查看hr目錄權限 -d 查看目錄 drwxrwx---. 2 root hr 4096 3月 13 14:26 /home/hr/ 4.rwx對文件的影響 實戰案例1:rwx對文件的影響[root@lxw ~]# vim /home/file1 //vim進入file1文件 date [root@tianyun ~]# ll /home/file1 //查看file1文件權限 -rw-r--r-- 1 root root 5 7月 26 14:43 /home/file1 [root@lxw ~]# chmod o+x /home/file1 //給予file1文件其他人x執行權限 [root@lxw ~]# chmod o+w /home/file1 //給予file1文件其他人w寫權限 [root@lxw ~]# su - alice //切換至alice用戶 [alice@lxw ~]$ cat /home/file1 //測試讀,可執行 [alice@lxw ~]$ /home/file1 //測試執行 -bash: /home/file1: 權限不夠 [alice@lxw ~]$ /home/file1 2017年 07月 26日 星期三 14:46:29 CST [alice@tianyun ~]$ vim /home/file1 //測試寫 date ls實戰案例2:對目錄沒有w,對文件有rwx [root@lxw ~]# mkdir /dir10 //創建dir10 目錄 [root@lxw ~]# touch /dir10/file1 //創建file1 文件 [root@lxw ~]# chmod 777 /dir10/file1 //賦權file1 777權限[root@lxw ~]# ll -d /dir10/ //查看diir10目錄權限 drwxr-xr-x. 2 root root 4096 3月 11 18:37 /dir10/ [root@lxw ~]# ll /dir10/file1 //查看file1文件權限 -rwxrwxrwx. 1 root root 0 3月 11 18:37 /dir10/file1[alice@lxw ~]$ cat /dir10/file1 //讀執行成功 [alice@lxw ~]$ rm -rf /dir10/file1 //執行權限失敗 rm: 無法刪除"/dir10/file1": 權限不夠實戰案例3:對目錄有w,對文件沒有任何權限[root@lxw ~]# chmod 777 /dir10/ //賦予dir10 777權限 [root@lxw ~]# chmod 000 /dir10/file1 //賦予file1 000權限 [root@lxw ~]# ll -d /dir10/ //查看dir10權限 drwxrwxrwx. 2 root root 4096 3月 11 18:37 /dir10/ [root@lxw ~]# ll /dir10/file1 //查看file1權限 ----------. 1 root root 0 3月 11 18:37 /dir10/file1[alice@lxw ~]$ cat /dir10/file1 //alice 查看r權限不夠 cat: /dir10/file1: 權限不夠 [alice@lxw ~]$ rm -rf /dir10/file1 // 執行x權限刪除成功 [alice@lxw ~]$ touch /dir10/file2 // 寫w權限創建成功對目錄有w權限,可以在目錄中創建新文件,可以刪除目錄中的文件(跟文件權限無關)注意事項文件: x 權限小心給予目錄: w 權限小心給予再次認識一下文件和目錄:三.基本權限ACL
文件權限管理之: ACL設置基本權限(r、w、x)
UGO設置基本權限: 只能一個用戶,一個組和其他人
ACL 設置基本權限: r,w,x
ACL基本用法
設置:
當發現文件的權限后出現+ 號,說明有 facl 權限
[root@lxw ~]# touch /home/test.txt //創建test.txt [root@lxw ~]# ll /home/test.txt //查看test.txt權限 -rw-r--r-- 1 root root 0 10-26 13:59 /home/test.txt[root@lxw ~]# getfacl /home/test.txt //查看acl權限 [root@lxw ~]# setfacl -m u:alice:rw /home/test.txt //增加用戶alice權限 [root@lxw ~]# setfacl -m u:jack:- /home/test.txt //增加用戶jack權限 [root@lxw ~]# setfacl -m o::rw /home/test.txt [root@lxw ~]# setfacl -x g:hr /home/test.txt //刪除組hr的acl權限 [root@lxw ~]# setfacl -b /home/test.txt //刪除所有acl權限[root@lxw ~]# man setfacl //man 手冊 查看幫助信息 //EXAMPLES,示例 [root@lxw ~]# getfacl file1 |setfacl --set-file=- file2 //復制file1的ACL權限給file2四.高級權限
高級權限suid,sgid,sticky
1.1.高級權限的類型
suid 4
sgid 2
sticky 1 粘滯位
1.2.設置特殊權限
a、字符
chmod u+s file //u 與文件屬主擁有一樣的權限
chmod g+s dir //g 與和文件屬主同組的用戶擁有一樣的權限
chmod o+t dir // o 與其他用戶擁有一樣的權限
b、數字
chmod 4777 file
chmod 7777 file
chmod 2770 dir
chmod 3770 dir
suid 普通用戶通過suid提權 <針對文件>
在進程文件(二進制,可執行)上增加suid權限
[root@tianyun ~]# chmod u+s /usr/bin/cat
[root@tianyun ~]# chmod u+s /usr/bin/rm
[alice@tianyun ~]$ cat /root/file1.txt
Sgid權限
chmod g+s dirname ## 當一個目錄擁有sgid權限,則該目錄下新創建的文件或者目錄都繼承該目錄的屬組
**Sticky 權限 **
在該目錄下的文件只能有改文件的所有者和目錄的所有者以及root 來刪除Chmod o+t dirname 在該目錄下的文件只能有 該文件的所有者 和目錄
本文章純屬個人學習心得總結,希望大家相互學習,后續會持續跟新,謝謝大家的 觀看!
總結
以上是生活随笔為你收集整理的Linux云计算【第一阶段】第四章:权限管理的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: UE4动画系统笔记
- 下一篇: linux 其他常用命令