0

I want to mount a file as read-only and anybody cant write to this file.

I research in internet and find some commands:

 mount -o remount,ro /dev/sda6 /srv/html

and

mount -o remount,rw /dev/sda6 /srv/html

but this for file system and partitons.

How to mount a file as read-only?

Thank you.

Easy Dns Name
  • 19
  • 2
  • 3

1 Answers1

0

How about a mount bind?

$ touch a
$ echo "Hello World" >> a
$ pwd
/home/nwani
$ mkdir -p /tmp/readonlydir
$ sudo mount -o ro,bind /home/nwani/ /tmp/readonlydir/
$ echo "Hello World" >> /tmp/readonlydir/a
-bash: /tmp/readonlydir/a: Read-only file system
$ 
Nehal J Wani
  • 16,071
  • 3
  • 64
  • 89