Linux 權限模型除基礎的 rwx 外,還包含三個特殊權限位:Setuid、Setgid、Sticky Bit。它們在安全控制、協作目錄、提權執行等場景中扮演關鍵角色。本文結合系統實例深度解析原理與應用。
/usr/bin/passwd-rwsr-xr-x 1 root root 23420 /usr/bin/passwd
-rw-r--r-- 1 root root 2005 /etc/passwd
/etc/passwd 僅 root 可寫passwd 時,因二進制文件帶 Setuid(s 位於所有者 x 位),進程臨時獲得 root 權限,從而能修改密碼文件g+s,顯示於組 x 位)ping、su、sudo、mountg+s 使新建文件自動繼承目錄所屬組,配合 umask 002 實現組內無縫協作/tmpdrwxrwxrwt 13 root root 4096 /tmp
rwxrwxrwx)/tmp 下的臨時文件| 權限 | 符號模式 | 數字模式 | 查看標識 |
|---|---|---|---|
| Setuid | chmod u+s file | chmod 4755 file | 所有者 x 位顯示 s(無 x 顯示 S) |
| Setgid | chmod g+s file/dir | chmod 2755 file | 組 x 位顯示 s(無 x 顯示 S) |
| Sticky Bit | chmod o+t dir | chmod 1755 dir | 其他者 x 位顯示 t(無 x 顯示 T) |
x,設置特殊位後顯示大寫,特殊權限不生效。須先 chmod +x 再加特殊位g+s 後,新建文件/子目錄自動繼承目錄所屬組find / -perm -4000 -type f# 查找所有 Setuid 文件
find / -perm -4000 -type f -ls 2>/dev/null
# 查找所有 Setgid 文件/目錄
find / -perm -2000 -type f -ls 2>/dev/null
# 查找所有 Sticky Bit 目錄
find / -perm -1000 -type d -ls 2>/dev/null