0

I put a 64-bit ELF file in my unprivileged user's home directory. I wonder which permissions do I need to have only possiblity to rename this file being logged in as unprivileged user. From what I understand I only need execute permission for user to whom file belongs to, set for parent's directory. Is that right?

So if path to my file is /home/Simon_dir/zip and I wrote chmod 0100 /home/Simon_dir and file permissions are set to 0000, should I have rights to rename the zip file being logged in as unprivileged user?

7

Generally, if you have write permission to a directory you can rename any file in that directory. Specifically, you do not have to own the file to be able to rename it:

ls -la
total 8
drwxr-xr-x  2 roaima roaima 4096 Mar 25 23:42 .
drwxr-xr-x 39 roaima roaima 4096 Mar 25 23:42 ..
-rw-------  1 root   root      0 Mar 25 23:42 file

mv file sandpaper
ls -l
total 0
-rw------- 1 root root 0 Mar 25 23:42 sandpaper

The exception is when an ACL has been applied that denies the operation, or when the sticky bit t is also present in that directory's permissions. In this second case you must also own the file to be renamed.

Note that in all cases you need access to the directory in question, so the appropriate execute bit x is required (user/group/others).

This means that the minimum set of permissions on a directory to rename any file in it is -wx for the appropriate membership set (user/group/others).

  • 1
    Since the question specifies minimum file permissions, you may want to mention that the execute bit is required as well. – Wildcard Mar 25 '16 at 23:19
  • What I'm trying to accomplish is renaming file with minimum permissions set for file and its directory to have possibility to rename it. From what I understood , I should give only write permission by 'chmod 0200 /home/Simon_dir' and file's permissions are set by 'chmod 0000 zip'? Should I be able to rename file while I'm not on root now? As I tried it and it didn't work , also sticky bit is not set on ;/ – sh1nen Mar 25 '16 at 23:23
  • @Wildcard thank you. Answer amended; please feel free to tweak as you see fit. – roaima Mar 25 '16 at 23:45
  • @sh1nen you need write and execute permission on a directory to rename any file in that directory. You do not need any access to the file itself. – roaima Mar 25 '16 at 23:47

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.