To give a user only read permission to a file or directory using Access Control Lists (ACL), you can use the setfacl command. ACLs allow you to set more granular permissions beyond the traditional file permission system.
1. Check Current ACLs (Optional)
Before making changes, check the existing ACLs for the file or directory:
getfacl filename
2. Set Read-Only Permission
To give a user read-only access to a file:
sudo setfacl -m u:username:r filename
To give a user read-only access to a directory:
sudo setfacl -m u:username:rX directoryname
3. Verify the ACL
Check the updated ACL to ensure the permissions were applied:
getfacl filename
Expected output:
# file: filename
# owner: ownername
# group: groupname
user:username:r--
4. Recursive Application (Optional)
If you want to apply the read-only permission to all files and subdirectories within a directory:
sudo setfacl -R -m u:username:rX directoryname
5. Remove ACL Permission
If you need to revoke the user's read-only permission later:
sudo setfacl -x u:username filename
By using the above steps we can easily manage access control of files and directories for users.
Ready to transform your business with our technology solutions? Contact Us today to Leverage Our DevOps Expertise.
0