Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

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
    
Possible solution: askubuntu.com/questions/33566/… –  chronitis Oct 3 '13 at 8:46
3  
Duplicate of superuser.com/questions/653739 and unix.stackexchange.com/questions/93399. Please don't cross post! –  David Foerster Oct 3 '13 at 9:11
    
How can you accept two different solutions in the two sites? Are they both working? –  don.joey Oct 3 '13 at 10:59
    
@don.joey Yes both are correct solutions. –  Manav Oct 3 '13 at 12:43
add comment

2 Answers 2

up vote 2 down vote accepted

chmod +t [FILE]

It sets the sticky bit, which does exactly what you describe.

EDIT: Well, to be more specific it prevents other users from renaming the file. So depends on what you want, exactly.

share|improve this answer
add comment

Quoting Stephane Chazelas from this answer on Unix & Linux SE.

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
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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