getfacl & setfacl 筆記

呃…用很久 linux 現在才知道可以用 getfacl & setfacl 指令,之前都用 chmod & chown 很難用,而且都要透過系統管理者。

假設我有一個 test 目錄權限是750

[sam@liho ~]$ ls -ld test
drwxr-x--- 2 sam sam 4096 Jun 18 18:08 test

先來用 getfacl 看看原本的設定是怎樣的

[sam@liho ~]$ getfacl test
# file: test
# owner : sam
# group : sam
user::rwx
group::r-x
other::- - -

如果我要設定 test 目錄可以讓 john 讀取可以用下列指令

[sam@liho ~]$ setfacl -Rm u:joe:rx test

這樣 john 就可以去 test 目錄讀取檔案 -m 是修改權限 -R 是遞迴設定權限

如果要讓 bob 有讀寫權限就用下面的指令

[sam@liho ~]$ setfacl -Rm u:bob:rwx test

檢查看看剛剛設定的值是否有正確

[sam@liho ~]$ getfacl test
# file: test
# owner : sam
# group : sam
user::rwx
user:bob:rwx
user:john:r-x
group::r-x
other::- - -

如果要移除 john 的權限,用下列指令就可以移除了

[sam@liho ~]$ setfacl -Rx u:john test

Leave a Reply

Your email address will not be published. Required fields are marked *

 

This site uses Akismet to reduce spam. Learn how your comment data is processed.