On file systems the process's user identifier (effective UID) is the principal means of control.
Why ACL required?
Usually UNIX read, write, execute permission are more than sufficient but in many cases you need to setup a complex permission for accessing files. ACL makes managing permissions quite easy under FreeBSD (and Linux).
Prepare filesystem to use ACL
To use ACLs under FreeBSD, remount filesystem with acls option:
Code:
# mount -o acls -u /usr
Code:
vi /etc/fstab
Code:
/dev/ad0s1f /usr ufs rw,acls 2 2
Code:
# sync;sync # reboot
Code:
# mount
Task: Set ACL using setfacl
The setfacl utility or command sets or modifies discretionary access control information on the specified file.
Each ACL is made of 3 tags. It contains colon-separated fields as follows:
tag:qualifier:access-permissions
=> tag field is use to setup user, group or other permission. It can consists of one of
the following
- u - specifying the access granted to the owner of the file or a specified user
- g - specifying the access granted to the file owning group or a specified group
- o - specifying the access granted to any process that does not match any user or group
=> access-permissions field contains up to one of each of the following:
- r : set read permission
- w : set write permission
- x : set execute permissions
Each of these may be excluded or placed with a '-' character to indicate no access.
In short use following syntax for each group of users to setup ACL:
To setup user/owner ACL
Code:
u:user-name:mode
Code:
g:group-name:mode
Code:
o:mode
Use getfacl command to display ACL information.
Code:
$ getfacl file.txt
#owner:1001
#group:1001
user::rw-
group::r--
other::r--
Task: set new ACL for user/owner
Sets read only permissions for the file called file.txt for owner:
Code:
setfacl -m u::r file.txt
Code:
getfacl file.txt
#owner:1001
#group:1001
user::r--
group::r--
mask::r--
other::r--
Now Sets read, write, and execute permissions for the file called file.txt for owner:
Code:
setfacl -m u::rwx file.txt getfacl file.txt
Code:
touch file2.txt getfacl file2.txt getfacl file.txt
Code:
getfacl file.txt | setfacl -b -n -M - file2.txt getfacl file2.txt