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