咱們都知道linux系統是多用戶、多任務的操做系統,用戶管理和權限管理參考http://2148fa7e.wiz03.com/share/s/0xifF-0vJQcD2FDV9W2F5M9r1aFl-f0ZNQvj2HbV7c277fDm 今天咱們將對linux系統原有權限進行補充。
r w x -> 4 2 1
當咱們建立用戶和文件的時候,沒有設置任何權限,可是文件或者用戶都已經有了權限,這些權限是從哪裏來的呢?能夠修改這些默認權限嗎?固然是能夠的。
umask是指定目前用戶在建立文件或目錄時權限的默認值。
# 查看權限默認值(與通常權限有關的是後面三個數字) umask # 使用鍵值對的方式顯示, user、group、other的權限綁定。-S ( Symbolic ) umask -S # u=rwx,g=rwx,o=rx
沒錯,linux文件系統除了支持9位的普通權限外,還有隱藏屬性。不要小看隱藏屬性,對於系統的安全(Security)很是重要。 主要是lsattr和chattr兩個命令來實現。
注意: chattr命令只能在ext二、ext三、ext4的linux傳統文件系統上完整生效。最新的xfs文件系統上僅支持部分命令。
屬性設置常見的是a和i的設置值,設置該值須要使用root權限纔可以設置。 xfs 文件系統僅支持 AadiS參數。
[root@study ~]# chattr [+-=][ASacdistu] 文件或目錄名稱 選項與參數: + :增長某一個特殊參數,其餘本來存在參數則不動。 - :移除某一個特殊參數,其餘本來存在參數則不動。 = :設置必定,且僅有後面接的參數 A :當設置了 A 這個屬性時,若你有存取此文件(或目錄)時,他的存取時間 atime 將不會被修改, 可避免 I/O 較慢的機器過分的存取磁盤。(目前建議使用文件系統掛載參數處理這個項目) S :通常文件是非同步寫入磁盤的(原理請參考前一章sync的說明),若是加上 S 這個屬性時, 當你進行任何文件的修改,該更動會「同步」寫入磁盤中。 a :當設置 a 以後,這個文件將只能增長數據,而不能刪除也不能修改數據,只有root 才能設置這屬性 c :這個屬性設置以後,將會自動的將此文件「壓縮」,在讀取的時候將會自動解壓縮, 可是在儲存的時候,將會先進行壓縮後再儲存(看來對於大文件彷佛蠻有用的!) d :當 dump 程序被執行的時候,設置 d 屬性將可以使該文件(或目錄)不會被 dump 備份 i :這個 i 可就很厲害了!他可讓一個文件「不能被刪除、更名、設置連接也沒法寫入或新增數據!」 對於系統安全性有至關大的助益!只有 root 能設置此屬性 s :當文件設置了 s 屬性時,若是這個文件被刪除,他將會被徹底的移除出這個硬盤空間, 因此若是誤刪了,徹底沒法救回來了喔! u :與 s 相反的,當使用 u 來設置文件時,若是該文件被刪除了,則數據內容其實還存在磁盤中,可使用來恢復文件。
attr 使用
# 查看文件隱藏屬性 [root@localhost custom-user]# lsattr ---------------- ./1.txt ---------------- ./2.txt ---------------- ./3.sh ---------------- ./tmp # 設置文件隱藏屬性 [root@localhost custom-user]# chattr +a 1.txt [root@localhost custom-user]# lsattr -----a---------- ./1.txt ---------------- ./2.txt ---------------- ./3.sh ---------------- ./tmp
權限名稱 | 做用範圍 | 符號 | 權限制 | 描述 |
---|---|---|---|---|
SET UID | 二進制文件 | s | 4 | 1. SUID 權限僅對二進制程序(binary program)有效; 2. 執行者對於該程序須要具備 x 的可執行權限; 3. 本權限僅在執行該程序的過程當中有效 (run-time); 4. 執行者將具備該程序擁有者 (owner) 的權限。 |
SET GID | 二進制文件/文件夾 | s | 2 | 文件: 1. SGID 對二進制程序有用; 2. 程序執行者對於該程序來講,需具有 x 的權限; 3. 執行者在執行的過程當中將會得到該程序羣組的支持! 文件夾: 1. 使用者若對於此目錄具備 r 與 x 的權限時,該使用者可以進入此目錄; 2. 使用者在此目錄下的有效羣組(effective group)將會變成該目錄的羣組; 3.用途:若使用者在此目錄下具備 w 的權限(能夠新建文件),則使用者所建立的新文件,該新文件的羣組與此目錄的羣組相同。 |
Sticky Bit | 文件夾 | t | 1 | 1. 當使用者對於此目錄具備 w, x 權限,亦即具備寫入的權限時; 2. 當使用者在該目錄下建立文件或目錄時,僅有本身與 root 纔有權力刪除該文件。 |
SUID 執行過程
![]()
一樣支持數字設置和符號設置linux
# 數字設置 -- beign -- [root@localhost custom-user]# chmod 4777 3.sh [root@localhost custom-user]# ll 3.sh -rwsrwxrwx 1 custom-user custom-group 21 2月 14 16:46 3.sh # 去除user的s [root@localhost custom-user]# chmod 0777 3.sh [root@localhost custom-user]# ll 3.sh -rwxrwxrwx 1 custom-user custom-group 21 2月 14 16:46 3.sh # 設置文件夾 [root@localhost custom-user]# mkdir tmp [root@localhost custom-user]# chmod 1777 tmp [root@localhost custom-user]# ll 總用量 8 drwxrwxrwt 2 root root 6 3月 8 03:08 tmp # 刪除文件夾的Sticky Bit [root@localhost custom-user]# chmod 0777 tmp/ [root@localhost custom-user]# ll 總用量 8 -rw------- 1 root root 0 2月 14 14:06 1.txt -r-xr--r-- 1 custom-user custom-group 889 2月 14 16:45 2.txt -rwxrwxrwx 1 custom-user custom-group 21 2月 14 16:46 3.sh drwxrwxrwx 2 root root 6 3月 8 03:08 tmp # 給沒有x權限的文件增長s權限 [root@localhost custom-user]# chmod 4677 3.sh [root@localhost custom-user]# ll 3.sh -rwSrwxrwx 1 custom-user custom-group 21 2月 14 16:46 3.sh ############ 注意: 這個時候咱們發現S變成了大寫。這說明s沒有生效,也就是說 s和t都是在 x基礎之上的權限,沒法獨立設置。 ############ # 數字設置 -- end -- # 符號設置 -- beign -- # 設置SUID [root@localhost custom-user]# chmod 777 1.txt [root@localhost custom-user]# chmod u+s 1.txt [root@localhost custom-user]# ll 1.txt -rwsrwxrwx 1 root root 0 2月 14 14:06 1.txt # 設置SGID [root@localhost custom-user]# chmod g+s 1.txt [root@localhost custom-user]# ll 1.txt -rwsrwsrwx 1 root root 0 2月 14 14:06 1.txt # 設置Sticky Bit [root@localhost custom-user]# chmod o+t tmp [root@localhost custom-user]# ll 總用量 8 -rwsrwsrwx 1 root root 0 2月 14 14:06 1.txt -r-xr--r-- 1 custom-user custom-group 889 2月 14 16:45 2.txt -rwSrwxrwx 1 custom-user custom-group 21 2月 14 16:46 3.sh drwxrwxrwt 2 root root 6 3月 8 03:08 tmp # 符號設置 -- end --