[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 234
  • Last Modified:

protect a file from delete

How can I set a file permission so only the user can delete it?
0
rbruno_elliott
Asked:
rbruno_elliott
1 Solution
 
bedotCommented:
chmod 644 the_file

IE:
root@med1091[/tmp]> tst
root@med1091[/tmp]ls -l tst
-rw-rw-rw-   1 root       sys              0 Dec  3 13:56 tst
root@med1091[/tmp]chmod 644 tst
root@med1091[/tmp]ls -l tst
-rw-r--r--   1 root       sys              0 Dec  3 13:56 tst
so, the file can be read by owner, group, and all
can be writed (and deleted) by the owner

beware : this file situated in the directory that belong at an other user can generally be destroyed by the owner of the directory; you must in this case set the bit t on this directory (meaning only the owner of the file can delete it);
in some systems even this maneer is unsufficent, and the disrectory must belong at the owner of the file;

not very nice!


0
 
rbruno_elliottAuthor Commented:
Sorry I should have included the following diatribe

Actually I need the file to be writable but not deletable by the group and others.  I only want the user to be to completely delete the file.  I thought there was a command which allowed you to accomplished this.  Keeping in mind that if you can write to it you could essentially erase all the data.

Reason:

I have a spredsheet file that is used by quite a number of people and somebody keeps deleting accidently.  Whoever is doing this is unaware that they are deleting it.  If they had write access but not delete access (completely removing the file) I think it would solve my problem.

Sorry about not being specific enough in the original question.  
0
 
ArtimageCommented:
What you need to do is make the directory the file resides in not writable by the offending person.

For instance
chmod 755 test/

now people can read and write files in test, but they can't delete those files.

Artimage.-
0
Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

 
rbruno_elliottAuthor Commented:
The original reply from Bedot is more what I am looking for.  Although I can not really say that this reply won't work.  We are having majot network problems and have been unable to verify anything


Setting the bit t is what I think I'm looking for.

If I do a

chmod o+g-t filename

Will this allow only the user to delete the file?

 
0
 
chintuCommented:
the simplest solution is the solution that has been mentioned already of using
the sticky bit "t" for the directory where
this file resides. this will allow other users/group ID
to write to the file ( with correct file permissions )
for example chmod 664 filename
and
chmod 1755 <directory name> ( where file resides )

Owner+ Group can write to the file, but only
owner can delete it.

The problem here is anyone who has access to
write to the file can wipeout the file without deleting the file.

I would suggest you use some kind of revision control mechanism.. say sccs, rcs, cvs etc. where a person can checkout the file modify it and checkback in when this done. This will also maintail the revisions of the file and every change made to it.

There is one more option for you.  You can write scripts or alias the commands that users use to access this file.  So that everytime someone opens the file for modification, they make a backup copy of the file before they even get to the editing part.
This way if someone deletes the file, or wipes out the data, you still  have one or more backup copy.

If you need any specific data, please let me know.
0
 
rbruno_elliottAuthor Commented:
Thanks a lot that will do the trick.
0
 
manojaminCommented:
hey! what about the chintu's points????
0
 
cjrd99Commented:
A file on unix delete permission on unix is not controlled by the permissions of the file it self but
the permissions of the owner of the directory the file resides in.

To protect it from deletion by any other than the owner simply set the
directory permissions to :

chmod 755 user_dir

To affect the file :
 cd to user_dir and set the permissions as desired.
0
 
rbruno_elliottAuthor Commented:
Thanks sounds good to me.

I'm looking to accept Chintus answer because he was first.
He got me there already but I've been unable to go back and give him credit.

Thanks though.

Sorry
0
 
rbruno_elliottAuthor Commented:
I would like to give the credit to Chintu for giving me the
first answer for exactly what I was looking for but have
been unable to do so.
I wasn't given the option to accept or reject on that 1 just to
read it.

 Also cjrd99's response was very helpful too.
If I could give them both a good grade and points I would like to.  All I need to know now is how to do that.
0
 
chintuCommented:
Use my previous comments as the answer
0
 
rbruno_elliottAuthor Commented:
Thanks a lot
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now