Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

For some special purpose, I want to prevent non-root users of the Linux Server from changing or renaming the filenames. However, they can modify and write to the contents of the file. How to do this from command line.

share|improve this question

closed as off-topic by jasonwryan, Michael Kjörling, Anthon, slm, Patrick Oct 3 '13 at 12:40

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "This question has been posted on multiple sites. Cross-posting is strongly discouraged; see the help center and community FAQ for more information." – jasonwryan, Michael Kjörling, Anthon, slm, Patrick

Use chattr command. – Sepahrad Salour Oct 3 '13 at 8:47
Duplicate of superuser.com/questions/653739/…; please don't post on multiple sites simultaneously! – Ingo Karkat Oct 3 '13 at 8:49
up vote 8 down vote accepted

To rename a file, write permissions to the file don't matter, renaming a file is a change to the directory, not the file. That's changing the directory entry to have a different name pointing to the file.

So all you need to do is change the permissions of the directory. For instance:

chown root: .
chmod 755 .

That will prevent users from renaming files in there, but also from creating or deleting files. If you still want them to be able to do that, you could instead make the directory writeable but also set the t bit. With that bit set, users (other than the owner of the directory who is not restricted) can only delete or rename the files they own.

chown root:people-who-can-create-file-here .
chmod 1775 .
chown root:people-who-can-modify-the-files file1-that-must-not-be-rename ...
chmod 664 file1-that-must-not-be-rename ...
share|improve this answer

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