Operating System - HP-UX
1826004 Members
3393 Online
109690 Solutions
New Discussion

Re: Restrict user to delete file

 
SOLVED
Go to solution
ust3
Regular Advisor

Restrict user to delete file

I hv a file that users from different group will update it , so I set it to mode 666 , if I don't want anyone have the permission to delete this file , only file owner can delete it , can advise how to set it ? thx
4 REPLIES 4
Court Campbell
Honored Contributor
Solution

Re: Restrict user to delete file

If you set the sticky bit on the directory that the file is located in then only the owner of the file and the superuser can remove the file. You may want to create a shared folder and set the group to the group of users that need to modify the files. then set the sgid and sticky bit on the directory. This way only the person that created the file can delete it, but the group will be given perms to read/write to the files.
"The difference between me and you? I will read the man page." and "Respect the hat." and "You could just do a search on ITRC, you don't need to start a thread on a topic that's been answered 100 times already." Oh, and "What. no points???"
Ninad_1
Honored Contributor

Re: Restrict user to delete file

If the users do not have write privilege to the directory in which this file exists, then the users would not have permission to delete this file.
But note that since users have write permission to this file, they can still delete the contents of the file.

Regards,
Ninad
hangyu
Regular Advisor

Re: Restrict user to delete file

thx replies ,

( the question is posted by me )

I try to "chmod +t" to a file , and make sure the file with "t" (-rwxr-xr-t) mode , but still found other user can delete this file ( I also check if add "t" mode to a directory , the other user CANNOT delete file in it ) , can advise how to add a sticky bit to a file ( not directory ) ? thx
Ninad_1
Honored Contributor

Re: Restrict user to delete file

You can set sticky bit to file exactly same as the directory, except for dir name give the filename.
But sticky bit on file is not to restrict access to file but usually defined to keep an executable file in memory even after execution is completed [ thus stick into the memory ] so that later invocation can take the executable from the memory rather than do seeks on disk to get the file. This is done for files which would be very often used for execution.

Regards,
Ninad