DevOps

A Comprehensive Guide to Setting Up User Based Permissions in Linux


Introduction

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.

Read-Only Permission

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
  1. r: Read permission.
  2. X: Execute permission for directories only (needed for navigation).

 

3. Verify the ACL

Check the updated ACL to ensure the permissions were applied:

getfacl filename

 

Expected output:

# file: filename# owner: ownername# group: groupnameuser: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

 

Conclusion

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

Devops

Related Center Of Excellence