1

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?

EDIT

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 Mar 6 '15 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 Mar 6 '15 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 Mar 6 '15 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 Mar 6 '15 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 Mar 6 '15 at 23:27
0

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 ?

-1

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 Mar 6 '15 at 13:38
  • Right, how could I forget that. Probably because it was possible a few decades ago. – Janis Mar 6 '15 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) – Stéphane Chazelas Mar 9 '15 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 Mar 9 '15 at 15:50

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.