傳統 rwx 權限模型僅支援「擁有者/群組/其他」三元組,無法滿足多用戶協作的精細授權需求。ACL (Access Control List) 提供針對特定用戶/群組的獨立權限控制,支援 ext2/3/4、XFS、Btrfs 等主流檔案系統。
# Ubuntu/Debian apt-get install acl # CentOS/RHEL/Fedora yum -y install acl # Archlinux pacman -S acl
# 檢查現狀 mount | grep acl # 未啟用則編輯 /etc/fstab 加入 acl 掛載選項 UUID=xxx / ext4 defaults,acl 0 1 # 重新掛載生效 mount -o remount /
mkdir /shared # 目標:user test 完整權限,user test2 唯讀
# 給 test 完整權限 setfacl -m u:test:rwx /shared # 給 test2 唯讀(目錄需 x 進入) setfacl -m u:test2:rx /shared
# ls -lh /shared # 權限位後有 + 號表示含 ACL # getfacl /shared # 詳細 ACL 列表 # file: shared # owner: root # group: root user::rwx user:test:rwx user:test2:r-x group::r-x mask::rwx other::r-x
# 移除特定用戶 setfacl -x u:test /shared # 清除所有 ACL setfacl -b /shared
setfacl -m u:用戶名:權限 路徑
-m g:群組名:權限 路徑
-x u:用戶名 路徑 # 刪除
-b 路徑 # 清空
cp -p 保留 ACL,否則警告且不複製mv 預設移動 ACL,不可行時警告