Linux 檔案權限除基本 rwx 外,還有三個特殊權限位:SUID、SGID、Sticky Bit。本文詳細說明其作用、chmod 設定方法 (符號與數字模式) 並給出實戰演示。
/usr/bin/passwd (讓一般用戶修改自已密碼,實際寫入 /etc/shadow 需 root 權限)。/tmp (drwxrwxrwt),ls -ld /tmp 顯示 t 取代 others 的 x。# 建立測試腳本
vim kuqlan.sh
chmod 755 kuqlan.sh
ls -l kuqlan.sh
# -rwxr-xr-x 1 root root 17 kuqlan.sh
# 設定 SUID (4)
chmod 4755 kuqlan.sh
ls -l kuqlan.sh
# -rwsr-xr-x 1 root root 17 kuqlan.sh (owner x 變 s)
# 設定 SGID (2)
chmod 2755 kuqlan.sh
ls -l kuqlan.sh
# -rwxr-sr-x 1 root root 17 kuqlan.sh (group x 變 s)
# 同時設定 SUID+SGID (6)
chmod 6755 kuqlan.sh
ls -l kuqlan.sh
# -rwsr-sr-x 1 root root 17 kuqlan.sh
# 設定 Sticky Bit 於目錄
mkdir testdir
chmod 1777 testdir
ls -ld testdir
# drwxrwxrwt 2 root root 4096 ... testdir
chmod u+s file # SUID
chmod g+s file # SGID (檔案)
chmod g+s dir # SGID (目錄,繼承群組)
chmod +t dir # Sticky Bit
chmod -t dir # 移除 Sticky Bit
find / -perm -4000 -o -perm -2000。