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.

How can I restrict user from deleting files?

The user should have read and write rights, but the delete rights should be denied. In Windows the same task can be done easily, but I don't know the way to do this in Ubuntu.

share|improve this question
add comment

3 Answers 3

up vote 5 down vote accepted

You need an access control list to do this. Package is called acl Install acl

From the article:

An access control list (ACL), with respect to a computer file system, is a list of permissions attached to an object. An ACL specifies which users or system processes are granted access to objects, as well as what operations are allowed on given objects. Each entry in a typical ACL specifies a subject and an operation. For instance, if a file has an ACL that contains (Alice, delete), this would give Alice permission to delete the file.

There are 2 packages in Ubuntu to maintain the rules for ACL:

  1. sadms Install sadms

im

  1. eiciel Install eiciel

im3

The problem you will run into with chmod is that delete and write are considered the same: if you can write to a file you can empty it (and thus you can delete the contents).

Btw: the 1st package can also manage your samba settings ;)

share|improve this answer
    
Do you have any documentation about preventing deletion with ACL via the CLI? On help.ubuntu.com/community/FilePermissionsACLs it only lists read, write and execute. –  xZise Nov 16 '13 at 16:43
    
You can only delete a file if the -directory- has write access. –  Rinzwind Nov 16 '13 at 16:50
    
But for that I don't need ACLs (okay I could use them to automatically apply restrictions to files and directories in it). I also need to allow the user to create files and for that the directory need write access. –  xZise Nov 16 '13 at 16:52
add comment

This can be accomplished by giving user write permission on files only but not on directory. User will not be able to delete a file from directory if he doesnt have 'write' permissions on the directory its self.

Note that this will also apply on file creation. So without write permission on directory, user will be able to read/write files already existing in the directory but will not be able to create or delete any file.

UPDATE: The following screenshot shows what I am trying to say: enter image description here

share|improve this answer
    
I just want to do it for both files and directory.. –  karthick87 Jun 3 '11 at 11:55
    
@karthick87: didnt get you. If you mean that you dont want user to delete the directory then this will do this too as user has no rights to modify the directory. –  binW Jun 3 '11 at 11:58
    
The user should have the read and write option( like he can create files and directories,and he can move files and directories from one location to another location) but he should not able to delete files and directories. –  karthick87 Jun 3 '11 at 12:06
    
@binW I do not believe this will work in a way karthick87 wants: either you loose the ability to create or the ability to delete a file and he probably wants both (create, delete and write are related to eachother): if you can create you can delete and you can write to the file cuz you just own it. –  Rinzwind Jun 3 '11 at 12:23
    
@Rinzwind: if dont give user write permissions on the directory then user loses both i.e ability to create or delete a file. S/he can only edit files which are already in the directory. Its not that hard to try. Just create a test directory and create a test file in inside this directory. Now remove write permissions from the directory using "chmod a-w" and then try 1. creating a new file 2. Delete the test file which was already created and 3. Edit the test file –  binW Jun 3 '11 at 12:44
show 2 more comments

set read and write permissions to a group, so all members of that group can read and write.

make owner some other user, because the folder is owned by that user

set this other user's permission of the folder to sticky, only the owner can delete files in the folder

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.