I want to remove all write access to files & directories for any user or group while preserving other permissions. Is this possible?

  • Remount read-only? – Stéphane Chazelas Jun 9 '14 at 11:03
  • Would really prefer not to do that! Is there any way wild cards can be used in the user list? – rightwayround Jun 9 '14 at 11:10
  • 2
    On Linux, you can bind mount a specific directory over itself as read-only (mount --bind dir dir && mount --bind -o remount,ro dir). You can also make all the files owned root:root and chmod -R a-w dir. You can also set the immutable flag which will make the files unwritable regardless of the permissions. – Stéphane Chazelas Jun 9 '14 at 11:14
  • @StéphaneChazelas Read-only bind mounts have come and go over the years and the distributions… See the comments on unix.stackexchange.com/questions/128336/… and unix.stackexchange.com/questions/49800/…. Better not recommend them unless you know what distribution and kernel version are in use. – Gilles 'SO- stop being evil' Jun 10 '14 at 0:26

If you want to remove write access from everyone, you don't need ACLs: traditional permissions will do.

chmod -R a-w /path/to/directory

Note that users can change back the permissions of the files that they own (this would also apply to anything you do with ACL).

If you wanted to use ACL in order to preserve the traditional permissions of the files, you'd have to list every user of the system, or at least every group.

If the filesystem is ext2/ext3/ext4, you can set the immutable attribute. Only root can change the immutable attribute, and it prevents all writes.

chattr -R +i /path/to/directory

There's a good chance that your problem can be solved by mounting the directory in a private location and exposing a read-only view through bindfs. See read only access to all files in a specific sub-folder

| improve this answer | |
  • Note: you can't create hard links to files with immutable flag. However, you can set immutable flag to already hard linked files (you won't be able to remove or rename any of the linked files). I'm not sure if that behavior is the same in all distributions and file-systems. – lepe Sep 17 '15 at 3:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.