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
...CORRECTsudo ls /mnt/foo
works ..CORRECTls /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?
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