0

I have created directory as following:

root@host [~]#  mkdir mydir
root@host [~]#  ls -ld mydir
drwxrwxr-x 2 test test 4096 Mar 2 19:36 mydir
root@host [~]# 

Then I have changed the group ownership of the directory by using the 'chgrp' command, and then also added the ‘setgid’ permission.

root@host [~]#  chgrp test2 mydir/
root@host [~]#  chmod g+s mydir
root@host [~]#  ls -ld mydir/
drwxrwsr-x 2 test test2 4096 Mar 2 19:36 mydir/
root@host [~]# 

Now, when I create a file under the directory, I see the file is missing execute permission.

root@host [~]#  touch mydir/myfile3
root@host [~]#  ls -l mydir/myfile3
-rw-rw-r-- 1 test test2 0 Mar 2 19:59 mydir/myfile3
root@host [~]#

My understanding is that the file should get exactly same permission as the parent directory. And, the parent directory as rwx permission so the file should also get rwx permission.

meallhour
  • 169
  • 2
  • 6
  • to affect the permissions new files get, you need to either change the umask of the process creating the files, or use a default ACL. See e.g. [Getting new files to inherit group permissions on Linux](https://unix.stackexchange.com/q/115631/170373). But neither can force on a bit that the creating process doesn't want to set, e.g. the `x` bit for data files, or access by others for "private" files. See e.g. [Permissions set on new files and folders by default ACLs](https://unix.stackexchange.com/q/305893/170373) – ilkkachu Jan 25 '22 at 19:20

1 Answers1

3

The sgid bit on directories causes files created inside them to be owned by the group owning the directory, that’s all. You can see this in your example: myfile2 is owned by group test2.

The sgid bit doesn’t determine permissions on files created inside the directory.

Again, see Understanding UNIX permissions and file types for details.

Stephen Kitt
  • 411,918
  • 54
  • 1,065
  • 1,164