Working With ACLs
Updated: 07/15/2005
General Information
File servers that run Microsoft Windows will typically have the shared resources locked to some users/groups while other users/groups can have full rights on the same share. How can this be if standard permissions are generic for one user, one group, and everybody? This is accomplished with the use of Access Control Lists (ACLs) and the UNIX environment can also apply these variable permissions to files and directories. Not only can they support the feature, Windows clients that connect to your Samba shares will respect them as well.Requirements
Configuration
By default, ACL support is disabled on all partitions or mount points. We can verify this by viewing the mounting table.|
# mount /dev/ad1s1a on / (ufs, local) devfs on /dev (devfs, local) /dev/ad1s1e on /tmp (ufs, local, soft-updates) /dev/ad1s1f on /usr (ufs, local, soft-updates) /dev/ad1s1d on /var (ufs, local, soft-updates) |
/usr partition. In order to enable ACL support on any partition, it has to be unmounted first. Unmounting system partitions can only be done in single-user mode. Boot into single-user mode or if you are already in multi-user mode issue a shutdown.| # | shutdown now |
Note: Replace /dev/ad1s1f and /usr with the relevance partition and mountpoint for your system.
|
# umount /usr # tunefs -a enable /dev/ad1s1f tunefs: ACLs set # mount /dev/ad1s1f /usr |
|
# mount /dev/ad1s1a on / (ufs, local) devfs on /dev (devfs, local) /dev/ad1s1e on /tmp (ufs, local, soft-updates) /dev/ad1s1f on /usr (ufs, local, soft-updates, acls) /dev/ad1s1d on /var (ufs, local, soft-updates) |
| # | shutdown now |
Usage
Modify ACL
Now that ACL support is enabled on the /usr mountpoint, let's discuss using the feature on files and directories. We will be using two commands:setfacl(1) to set ACL information and getfacl(1) to display the ACL information. For this guide we will create a file for testing purposes.| # | echo "My file" > file.txt |
|
getfacl file.txt #file:file.txt #owner:1001 #group:0 user::rw- group::r-- other::r-- |
| # | setfacl -m u:bob:r,o:: file.txt |
|
# ls -l file.txt -rw-r-----+ 1 jon wheel - 8 Feb 21 00:16 file.txt |
|
getfacl file.txt #file:file.txt #owner:1001 #group:0 user::rw- user:bob:r-- group::r-- mask::r-- other::--- |
| # | setfacl -m u:bob:,o::rw file.txt |
Delete ACL
Now that you have ACLs set on files, over time you may need to change those permissions. Perhaps remove a user from the list altogether.| # | setfacl -n -x u:bob: file.txt |
| # | setfacl -bn file.txt |
|
ls -l file.txt -rw-r--rw- 1 jon wheel - 8 Feb 21 09:06 file.txt |
Copying ACLs
You might be thinking that ACLs are pretty neat, but how can a single one be applied to several files or a directory recursively? It's pretty simple. Just copy the ACL from one file to the next after setting up the original file.|
# setfacl -m u::rwx,g::rw,o::,u:bob:r file.txt # getfacl file.txt #file:file.txt #owner:1001 #group:0 user::rwx user:test:r-- group::rw- mask::rw- other::--- # touch file2.txt # getfacl file.txt | setfacl -b -n -M - file2.txt |
|
getfacl file.txt file2.txt #file:file.txt #owner:1001 #group:0 user::rwx user:test:r-- group::rw- mask::rw- other::--- #file:file2.txt #owner:1001 #group:0 user::rwx user:test:r-- group::rw- mask::rw- other::--- |
Author: Jon LaBass
jon at bsdguides dot org