The question in my assignment says this:

create a directory temp with all permissions for everybody, that cannot be deleted

and copy hello.sh in this directory giving execution rights for everybody, but hello.sh will be executed as the owner.

So I created a directory called temp and gave permissions like this:

chmod 555 temp

but when I try to cp hello.sh to temp I get an error as temp has the permissions 555. What does the professor exactly meant to ask here? How do I not allow a directory to be deleted but copy files into it?

  • What do you mean prof? Secondly who should not be able to delete the directory? – Karlson Feb 26 '12 at 2:46

Given that this is a homework assignment I won't give an exact answer but think about this: if you were given this assignment, that means that the setuid and sticky bits have been explained to you. That knowledge should be sufficient to complete this assignment.

  • 1
    thank you, I looked at sticky bit and setuid as soon as I saw your answer. Thanks! – varchar1 Feb 26 '12 at 17:49

Linux splits the permission settings into 3 groups:

  • Owner - The user who owns the file
  • Group - Set of users
  • World - Not owner and not part of Group

Following permission can be granted:

  • Read
  • Write
  • Execute

You can use chmod command to set the permissions for each group (Owner/User/World) by applying desired (Read/Write/Execute) tags to each one of them. The digits which are used to set the permissions are actually the decimal representation of the binary (0/1) flags which set per group. For example, you want to set permissions which will allow the following:

  • Owner - read, write and execute
  • Group - read and execute (but not write)
  • World - no permissions

So in that case for Owner we will have: read=1, write=1 and execute=1 resulting in permission:

111 -> 7

The Group will have: read=1, write=0 and execute=1 resulting in permission:

101 -> 5

And finally the World will have: read=0, write=0 and execute=0 resulting in permission:

000 -> 0

Additionally, you can set a what is called the sticky bit to a directory. It will prevent other users from deleting or renaming the files within that directory. Only the owner can delete or rename the files within that directory. So in your case, the correct chmod command will look like this:

chmod 1777 temp

Where 777 allows read/write/execute for all three groups and the additional 1 is the sticky bit.

  • None of this seems to explain how you could make a directory that's writable but not deletable – Michael Mrozek Feb 26 '12 at 8:54
  • @Michael Mrozek You're right. Modified my answer. – Eugene S Feb 26 '12 at 11:10
  • 110 -> 6 not 5. – Karlson Feb 26 '12 at 17:08
  • @EugeneS Thank you very much for your time to explain all this. – varchar1 Feb 26 '12 at 17:51
  • @Karlson My mistake. Fixed! – Eugene S Feb 26 '12 at 17:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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