Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

6
  • 2
    Files that are copied (e.g. by cp) are in fact newly created. If they don't inherit the group permission, the copying program is playing games, like copying to a temporary file and then moving it to the target directory. Commented Aug 4, 2015 at 15:30
  • 2
    @Kaz Good point. I updated the answer to clarify that it is cp -p that overrides the setgid setting. Commented Aug 4, 2015 at 17:55
  • 1
    But does cp -p override the setgid setting? On every single Unix implementation in existence? POSIX says that it is unspecified whether a failure to copy the user ID or group ID under cp -p results in a diagnostic message! However, the S_SUID and S_SGID bits, respectively, are required to be cleared in that situation (i.e. if a file is setuid bob, but bob's ownership can't be copied so that the file is owned by janet, don't make it setuid janet.) Commented Aug 4, 2015 at 20:58
  • 1
    "does cp -p override the setgid setting?" According to the POSIX spec, that is what it is supposed to do. It does so on all the Unix systems that I have used. You have quoted the part of the spec regarding what to do to protect security in the case when the group ID cannot be duplicated. I have never run into such a "cannot" situation, have you? Commented Aug 5, 2015 at 6:22
  • Some part of this answer is inaccurate. For example, cp -p does have the setgid effect on the file. Commented Apr 12, 2022 at 14:57