In myscript I have a line that does this :

chmod 660 somefile_given_as_argument_to_myscript

I gave the members of a group the right to exectute the script. (chmod 770 myscript) but when they execute the script on a file that belongs to me, it fails because they don't have the permission to change that file.

Can I add something to my script to give any member of the group the right to modify the permissions of any file that belongs to any member of the group?


As requested by some, I will precise why I want to do that. My ultimate goal is to allow any member of a group to read write any file in a given directory. I already posted another question but for now no good answer was given. I then thought that it would be possible for any user the change permission so that any member of the group could read write any file. But this does't work because one user cannot change permission of a file that belongs to someone else... The problem I have in my other post is that files that are created outside the shared directory and then moved/copied inside, don't have the right permission (I already changed the ACL of the shared directory).

  • Normally you can't chmod a file that doesn't belong to you. See here: superuser.com/questions/274756/… One solution would be to expose a read-only setuid executable to your group members. This executable could then wrap chmod calls as if you were doing them.
    – Brandin
    Commented Mar 6, 2015 at 13:41
  • @Brandin, thx but can you be more precise ? I don't really understand... do you mean that I should call chmod g+s on my executable that wrap chmod
    – PinkFloyd
    Commented Mar 6, 2015 at 14:27
  • Yes, if you want to be potentially unsafe/hackable, you can copy the system chmod into your home directory, set the setuid bit on that, and let your other team access it so that they can change permissions with it. e.g. cp /bin/chmod /pub/floyds_files/floydmod; chown floyd:wallteam chmod a+s,g+x,o-x floydmod Now your wallteam can run floydmod, which is the same as running chmod as you
    – Brandin
    Commented Mar 6, 2015 at 17:28
  • typos in above example -- it should be more like cp /bin/chmod /pub/floyds_files/floydmod; chown floyd:wallteam /pub/floyds_files/floymod; chmod a+s,g+x,o-x /pub/floyds_files/floydmod
    – Brandin
    Commented Mar 6, 2015 at 17:35
  • 2
    You can't chmod files you don't own. There is also no reason to do so. Please edit your question and explain what your final objective is, explain why you want to change the permissions. There is probably a better way to do it.
    – terdon
    Commented Mar 6, 2015 at 23:27

2 Answers 2


what you are looking for is umask(1)

In you case try umask 007 which will create file with no access to other.

Do you really need +x bit ?


The chmod command supports a s-flag: set user or group ID on execution (s). Formerly that was possible even on scripts, though newer Unixes disallow it on scripts for security reasons, so it may or may not fit in your environment.

  • 2
    setuid does not normally work on shell scripts. See here for more info unix.stackexchange.com/questions/364/…
    – Brandin
    Commented Mar 6, 2015 at 13:38
  • Right, how could I forget that. Probably because it was possible a few decades ago.
    – Janis
    Commented Mar 6, 2015 at 13:41
  • (hi Janis, welcome to Unix.SE BTW. Note that one advantage of SE over usenet is that one can more easily delete/amend one's answers) Commented Mar 9, 2015 at 15:06
  • Thanks for the welcome. I wanted to delete this answer but saw it would require five persons to do so. (I'll add some text now, but it probably would be better to just have it deleted.)
    – Janis
    Commented Mar 9, 2015 at 15:50

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .