-2

I want to lock a file(or read-only) so that anybody on server can't modify it. I find chattr command on Linux but I didn't use it for some reason.

I am using mount --bind file.log file.log, but after some day I need to unlock this file and use umount -l and rm -rf file.log but show this error

Device or resource busy.

When I reboot the server problem seems to be solved after reboot. Can you help me without reboot solve this problem?

  • Well, as Luis already mentioned, you should use your system as it is expected to be used. I also don't see why mount --bind file.log file.log should "lock" a file to be read only. Use chattr or chown and chmod for this task. If you can't unmount the bind mount, check with lsof file.log which process is accessing it and end that process. Then try to unmount it again. But I don't think that a bind mount will "lock" a file. – Thomas Sep 6 '16 at 10:42
1

If I've understood the problem correctly, what about if you chown root:root file, so that user root owns the file and then chmod 444 file, to disable any writing to it. This way, only root will be able to modify the file.

  • Thank you , but i dont use chmod and chown for some reason. – Easy Dns Name Sep 6 '16 at 10:15
  • fuser -m file.log will list all processes which are using the file . Then kill those processes to umount the file system . fuser -km file.log can also be used to kill the processes associated with the file. – Zama Ques Sep 6 '16 at 10: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.