How to use getfacl and setfacl to get and set access control lists (ACLs) on directories in Linux
https://www.zyxware.com/sites/default/files/styles/user_image/public/default_images/index.png?itok=2YmREnrP
BY sandeep.sasikumar
6 years ago
Linux
3
comments comment

The command "setfacl" refers to Set File Access Control Lists and "getfacl" refers to Get File Access Control List. Each file and directory in a Linux filesystem is created with a specific set of file permissions for its access. Each user can have different set of file access permissions. The permissions can be set using the setfacl utility. In order to know the access permissions of a file or directory we use getfacl. The getfacl command displays the access permissions of files and directories with file name, owner, group and the ACL's(Access Control List). When we create a directory it is created with a default set of access permissions and by using getfacl we will be able to see the access rights.

What are the default access permissions for a newly created directory?

To know this, first open a terminal and open the folder in which you want to create a subfolder. Next type "mkdir <folder-name>" and press the ENTER key. This will create a folder with default access permissions. To know the access permissions, type

getfacl <folder-name>

Now you will see the output of getfacl as something like the following:

# file: file-name
# owner:
# group: 
user::rwx
user:x:---
user:y:r--
group::r--
mask::rw-
other::---

Thus from the output of getfacl we will be able to see the access permissions of a file. In the above example, when we type getfacl <file-name>

the output will be shown as in the above format. It displays the owner of the file, the group which has access to it and also its various users and their access rights. In the above case the users are x and y, where the user 'x' is having no permission on this file and therefore it is shown with --- symbol indicating no read/write/execute permissions for the user x. Now considering the other user 'y’, it is having the permission r-- which means read-only rights. The default umask is set to rw- (read/write permissions).

How to copy the ACL of one folder to other?

Consider an example of copying the ACL of the directory named "x" to "y". For this, firstly we should know the ACL of the directory named "x". To obtain this type the command

getfacl x

This will display the ACL of the directory named "x" in the above mentioned format:

# file: x
# owner:
# group:
user::rwx
user:x:---
user:y:r--
group::r--
mask::rw-
other::---

To copy the ACL of one directory to the other we use the setfacl command. That is

setfacl --setfile =- y

As mentioned we want to copy the ACL of "x" to "y", for this we have to type the command

getfacl x | setfacl -R –setfile = -y

Here "getfacl x" will get the ACL of the directory named "x" and this output is given to the setfacl command using pipe. Thus getfacl will give the ACL of the directory "x" and

setfacl -R –setfile = -y

will set that ACL to the directory named "y". "-R" is used to set this ACL recursively.

How to inherit the ACL of parent directory to its child?

To copy the ACL of the parent directory to its child, use the following command

getfacl . | setfacl -R --setfile = -subdirectory_name

The "getfacl ." will get the ACL of the parent directory and setfacl will set that ACL to its sub-directories. Now for verification, type:

getfacl subdirectory_name

and also

getfacl directory_name

If both are same then the ACL of the sub-directory is same as the ACL of the parent.


RELATED ARTICLE

more_horiz
close

on 30th March 2007 / by webmaster
Ever since we started our pc sales and services division we have been trying to get a system with Hardware Linux Leave a reply Your email address will not be published. Required fields are marker * Cherry (not verified) access_time 17 Jul 2019 - 15:50 Is that true ? Are there many people who still use modems to dialup internet ? I was thinking of helping out with some limited internal modem support for NetBSD, but wasn’t sure what the user base is like. Anoop John (not verified) access_time 17 Jul 2019 - 15:50 Yes I have come across quite a few customers who still use dialup as the only means of accessing net. For people who just use internet to check mail, dialup is the cheapest way to go. shankar (not verified) access_time 17 Jul 2019 - 15:50 I have read your above article. I have the same problem. I want to use the new Bharatiya Operating System Solution (BOSS) which is linux based. My dial up modem of D-Link is not detected in linux/BOSS neither I can get a driver for linux. D-Link company have informed that they do not have any modem supporting linux. Please inform whether you can send it by post, cost and methods available for payment. regards, shankar Add new comment
more_horiz
close

on 04th April 2007 / by webmaster
Linux is the epitome of the FLOSS model. Linux Leave a reply Your email address will not be published. Required fields are marker * Dewey J. Corl (not verified) access_time 17 Jul 2019 - 15:50 Linux is not ready for the general public! (I am a Ubuntu user). For proof, 1. try to simply print labels on a Dymo label printer. It takes a LOT of work to get to the ease of label printing already available in Windows and Mac. 2. try syncing a modern Palm based PDA. Yes, jpilot and others will sync the main data, but pictures and midi files do not get transferred without a lot of extra setup. These are examples of applications that are not ready for the general public. Since an operating system only supports applications, Linux is not ready to be a common desktop for the general public. While we are waiting for the applications to catch up, keep up the good work!! Anoop John (not verified) access_time 17 Jul 2019 - 15:50 Dewey Yes you may be right. But these are not applications that a common man would use. A common man would use one of these applications - Internet browser, Chat Client, Email Client, Document Writer, Presentation Creator, Spreadsheet Editor, Movie Viewer, Music Player, CD/DVD Writer. Both examples you cited are more specific applications that only a small percentage of the whole population uses. It will take time before those hardware vendors identify the need from their perspective to address the Linux community. Krishnadas (not verified) access_time 17 Jul 2019 - 15:50 Dear Mr Anoop, Thank you very much for the free installation of LINUX done in my PC. I am getting immersed in the LINUX and seeing the versatility. To my surprise, I am able to read one of my old backup CD(wherein lot of my valuable file exist) done in DIRECT CD wizard (a custom cd writing software of Easy Cd creator in WIN98) which could not be read in XP. Installation of old version of easycd creator/direct cd program was not possible in XP. I thought that possible i lost all data. Very pleasant start! Srikanth N. S. (not verified) access_time 17 Jul 2019 - 15:50 Hi Anoop, My friend is thrilled with Ubuntu. One of his grouses with windows was that after OS installation, everything else is to be installed separately which is a real headache. WHereas if u install Linux, everything is installed as a package and he is thrilled to bits! Let linux installation spread in Trivandrum and your service in this direction is highly appreciated. Kepp up the good work Regards. PDA Freak (not verified) access_time 17 Jul 2019 - 15:50 Is it possible to install linux on a packardbell notebook ? Add new comment
more_horiz
close

on 20th April 2007 / by webmaster
Linux has been growing in leaps and bounds in terms of internationalization. Linux Malayalam Open Source Ubuntu Leave a reply Your email address will not be published. Required fields are marker * Ranjith Antony (not verified) access_time 17 Jul 2019 - 15:50 Everything is fine an dandy. However, to read those websites which doesn't support unicode fonts you have to install padma firefox extension . Those websites include all malayalam newspaper websites including, deepika, manorama, keralakaumudi etc. These websites only support truetype fonts. TrueTypes are glyphs matching a malayalam character but doesn't have a hex code assigned to it. They use ASCII character set but with a different glyph. Just to read malayalam, you only need to perform the first 3 steps in Peringodan's blog, in addition to the hacks thats been explained in this blog post. PS: Its so funny; a tutorial to explain how to install malayalam read and write support is written in malayalam. Thats what called a chicken and egg problem. Cherry (not verified) access_time 17 Jul 2019 - 15:50 I’d like to point out a couple of things: a) Malayalam support is not an Ubuntu thing or a Linux thing… I am running NetBSD -current on my laptop with x.org and I can type malayalam. Learning the key combinations is very easy and intuitive… it just requires attention and commitment. I learnt it in about a week and something. b) Mangleesh support for TeX has been around for a while. The TuX group in Trivandrum and specifically A.J.Alex have worked on very good quality latex support for malayalam. See: sarovar.org Just to set the record. Cheers, Cherry. vimal access_time 17 Jul 2019 - 15:50 Ready to use packages to support malayalam in Ubuntu 7.10 and Debian GNU/Linux Etch is available at http://malaylam.web4all.in . Add new comment
Leave a reply
Your email address will not be published. Required fields are marker *

Filtered HTML

  • Web page addresses and email addresses turn into links automatically.
  • Allowed HTML tags: <a href hreflang> <em> <strong> <cite> <blockquote cite> <code> <ul type> <ol start type='1 A I'> <li> <dl> <dt> <dd> <h2 id='jump-*'> <h3 id> <h4 id> <h5 id> <h6 id>
  • Lines and paragraphs break automatically.
The content of this field is kept private and will not be shown publicly.
CAPTCHA This question is for testing whether or not you are a human visitor and to prevent automated spam submissions.

author-image
ts (not verified)
access_time 17 Jul 2019 - 15:52

The above command:

getfacl x | setfacl -R –setfile = -y

must reaad like this to work:

getfacl x | setfacl -R –setfile=- y


author-image
TS (not verified)
access_time 17 Jul 2019 - 15:52

Forget about my previous post. This is the correct syntax now

getfacl x | setfacl -R –set-file=- y


author-image
anju rohilla (not verified)
access_time 17 Jul 2019 - 15:52

when we run the command like this
# setfacl -m u:anju:rw- /html
where anju is a user and html is a file in /.
then it changes the acess of the for group not for the user,why?