Skip to content Skip to sidebar Skip to footer

Ubuntu Give User Read Access to Folder

In a previous article, nosotros showed yous how to create a shared directory in Linux. Here, nosotros will describe how to give read/write access to a user on a specific directory in Linux.

There are 2 possible methods of doing this: the first is using ACLs (Access Control Lists) and the second is creating user groups to manage file permissions, every bit explained beneath.

For the purpose of this tutorial, we will utilise post-obit setup.

Operating system:          CentOS 7          Examination directory:          /shares/project1/reports          Test user:          tecmint          Filesystem type:          Ext4        

Make sure all commands are executed as root user or use the the sudo command with equivalent privileges.

Allow's start by creating the directory called reports using the mkdir command:

# mkdir -p /shares/project1/reports        

Using ACL to Give Read/Write Access to User on Directory

Of import: To apply this method, ensure that your Linux filesystem type (such as Ext3 and Ext4, NTFS, BTRFS) support ACLs.

one. Kickoff, check the current file system blazon on your system, and also whether the kernel supports ACL as follows:

# df -T | awk '{print $1,$two,$NF}' | grep "^/dev" # grep -i acl /kick/config*        

From the screenshot below, the filesystem type is Ext4 and the kernel supports POSIX ACLs as indicated by the CONFIG_EXT4_FS_POSIX_ACL=y option.

Check Filesystem Type and Kernel ACL Support
Bank check Filesystem Type and Kernel ACL Back up

ii. Next, check if the file system (partition) is mounted with ACL option or not:

# tune2fs -l /dev/sda1 | grep acl        
Check Partition ACL Support
Check Partition ACL Support

From the to a higher place output, nosotros can run into that default mount choice already has support for ACL. If in case it'due south not enabled, you tin enable it for the particular partition (/dev/sda3 for this case):

# mount -o remount,acl / # tune2fs -o acl /dev/sda3        

three. At present, its time to assign a read/write access to a user tecmint to a specific directory called reports by running the following commands.

# getfacl /shares/project1/reports       		  # Check the default ACL settings for the directory  # setfacl -thousand user:tecmint:rw /shares/project1/reports     # Requite rw access to user tecmint  # getfacl /shares/project1/reports    			  # Check new ACL settings for the directory        
Give Read/Write Access to Directory Using ACL
Give Read/Write Access to Directory Using ACL

In the screenshot to a higher place, the user tecmint now has read/write (rw) permissions on directory /shares/project1/reports every bit seen from the output of the second getfacl control.

For more information virtually ACL lists, do bank check out our following guides.

  1. How to Use ACLs (Access Control Lists) to Setup Disk Quotas for Users/Groups
  2. How to Use ACLs (Access Control Lists) to Mount Network Shares

Now let's meet the 2d method of assigning read/write access to a directory.

Using Groups to Give Read/Write Access to User on Directory

1. If the user already has a default user group (normally with same name as username), but change the group owner of the directory.

# chgrp tecmint /shares/project1/reports        

Alternatively, create a new group for multiple users (who will exist given read/write permissions on a specific directory), equally follows. Yet, this will create a shared directory:

# groupadd projects        

2. Then add together the user tecmint to the grouping projects as follows:

# usermod -aG projects tecmint	    # add together user to projects # groups tecmint	            # check users groups        

3. Alter the group owner of the directory to projects:

# chgrp	projects /shares/project1/reports        

iv. Now gear up read/write access for the grouping members:

# chmod -R 0760 /shares/projects/reports # ls  -fifty /shares/projects/	    #check new permissions        

That'south it! In this tutorial, we showed you how to give read/write access to a user on a specific directory in Linux. If whatsoever issues, do ask via the annotate department below.

If You Appreciate What Nosotros Do Here On TecMint, You lot Should Consider:

TecMint is the fastest growing and most trusted community site for any kind of Linux Manufactures, Guides and Books on the web. Millions of people visit TecMint! to search or browse the thousands of published articles available FREELY to all.

If you lot like what you are reading, delight consider buying u.s.a. a coffee ( or 2 ) as a token of appreciation.

Support Us

We are thankful for your never ending support.

bridgewaterfollnee.blogspot.com

Source: https://www.tecmint.com/give-read-write-access-to-directory-in-linux/

Post a Comment for "Ubuntu Give User Read Access to Folder"