Mount device as RW for root and RO for everyone else

I have a device I want to mount for root with full permissions and for everyone else as readonly. The man page tells me this is possible.

So:

  • sudo mkdir /mnt/foo
  • sudo mkdir /mnt/fooReadOnly
  • sudo chmod 700 /mnt/foo (rw for root only)
  • sudo chmod 444 /mnt/fooReadOnly (ro for everyone)
  • ensure device /dev/sdaX is mounted as /mnt/foo

Then I did what the man page suggested:

  • sudo mount --bind /mnt/foo /mnt/fooReadOnly
  • sudo mount -o remount,bind,ro /mnt/foo /mnt/fooReadOnly

Now to test:

  • ls /mnt/foo --> Permission denied ...CORRECT
  • sudo ls /mnt/foo works ..CORRECT
  • ls /mnt/fooReadOnly --> Permission denied ...INCORRECT?

How do I fix this?

Also, how do I add this to /etc/fstab so that it will automatically remount on boot?

6

1 Answer

First, unmount fooReadOnly with
sudo umount /mnt/fooReadOnly

Then, change the permission of fooReadOnly to 555
sudo chmod 555 /mnt/fooReadOnly
This is needed because entering a directory requires execute privilege.

Finally, remount fooReadOnly
sudo mount -o remount,bind,ro /mnt/foo /mnt/fooReadOnly

3

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

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

You Might Also Like