0

I have created a directory called newDir and changed the group it belongs to with mkdir newDir && chgrp test-group newDir.

I was user me when I did this.

Calling stat newDir produces expected output:

  File: newDir
  Size: 4096        Blocks: 8          IO Block: 4096   directory
Device: 801h/2049d  Inode: 10756102    Links: 2
Access: (0755/drwxr-xr-x)  Uid: ( 1001/      me)   Gid: ( 1003/test-group)
Access: 2018-01-27 17:03:07.514864274 +0100
Modify: 2018-01-27 17:03:07.514864274 +0100
Change: 2018-01-27 17:05:08.317543163 +0100
 Birth: -

Later, logged in as user otherUser, I tried to set the group ID (setgid) permission bit on the directory using chmod g+s newDir.

Disappointingly, I see with stat that the permissions haven't changed. I got no error on stderr, though, and the result of the chmod command is 0, as shown by echo $?.

Why did chmod g+s newDir have no effect?

I'm on Arch Linux 4.14.13.

  • 1
    So is the question asking why you got an exit status of zero or why the setgid failed? – roaima Jan 28 '18 at 23:04
  • @roaima: Why setgid failed. I edited the question to make this clear. – Matthias Braun Jan 29 '18 at 9:58
1

The reason chmod g+s newDir didn't succeed when executed as user otherUser, was that otherUser wasn't part of group test-group, which is the group of newDir.

Switching to a user that is part of test-group and doing chmod g+s newDir works just fine.

0

The add to Matthias' answer, if you wanted to do it numerically and absolutely, that'd be

chmod 2755 newDir

If you want to add yourself to the group you're targeting:

usermod -a -G otheruser test-group
newgrp

Sometimes newgrp doesn't seem to refresh groups, so you may need to relogin.

Weird that one has to be part of group they're trying to set the GUID bit for and that it fails without error, but that's how it is.

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.