Linux 傳統的 rwx 權限僅能針對「擁有者、群組、其他人」三類主體設定,無法針對單一使用者給予特殊權限。ACL(Access Control List)解決了這個痛點,支援對個別使用者或群組設定獨立權限,甚至能限制 root。以下為啟用與操作完整流程。
# grep -i acl /boot/config-$(uname -r)
CONFIG_EXT4_FS_ACL=y # 霵為 y 表示已編譯支援
若無支援,需重編核心或安裝 acl 套件(apt install acl / yum install acl)。
臨時掛載:
mount -t ext4 -o acl /dev/sda1 /fs1
永久生效:編輯 /etc/fstab,在對應分區選項加入 acl:
UUID=xxxx /fs1 ext4 defaults,acl 0 2
# 建立測試使用者
useradd test1; useradd test2; useradd test3
echo "pass" | passwd --stdin test1
echo "pass" | passwd --stdin test2
echo "pass" | passwd --stdin test3
# test1 建立檔案並移除群組/他人權限
su - test1 -c 'cd /fs1 && echo "Create by test1" > test1.txt && chmod 600 test1.txt'
# 僅授予 test2 讀寫權限
su - test1 -c 'setfacl -m u:test2:rw /fs1/test1.txt'
# 驗證
getfacl /fs1/test1.txt
# 輸出會顯示 user:test2:rw- 且檔案尾部出現 + 號,表示已套用 ACL
# test2 可讀寫,test3 被拒絕
su - test2 -c 'cat /fs1/test1.txt && echo "Modify by test2" >> /fs1/test1.txt'
su - test3 -c 'cat /fs1/test1.txt' # Permission denied
setfacl -m u:user:perm file:設定使用者 ACLsetfacl -m g:group:perm file:設定群組 ACLsetfacl -x u:user file:移除指定使用者 ACLsetfacl -b file:移除所有 ACLgetfacl file:檢視 ACL善用 ACL,即可在不更改傳統權限位的前提下,實現精細到「單一使用者/群組」的存取控制,滿足多使用者共存環境的安全需求。