In Linux there are SUID, SGID, and sticky bits for directory permissions.

I am absolutely clear about the sticky and SGID bit on files or folders.

But what happens if I apply SUID bit on a directory?

For example, if I apply a SGID bit on a file, a process that gets started with this file will use the effective group ID of the file's group and not the primary group of the user who is calling the file. Same thing if you apply the SUID bit on a file: it will run with the owner as the effective user.

This changes as soon as you apply the SGID bit on a directory, for example chmod -R 2770 /var/testdir/. Now all new files and folders what will be created within /var/testdir/ will inherit the same group as /var/testdir/ even if the creator's primary group is different. Also, subdirectories will inherit the SGID bit.

But what happens if you apply the SUID bit on a directory? I did not find any information for that case.

Also, what happens if you apply SGID and SGID bit on the same folder?


Solution 1:

GNU Coreutils: Directory Setuid and Setgid

27.5 Directories and the Set-User-ID and Set-Group-ID Bits

On most systems, if a directory’s set-group-ID bit is set, newly created subfiles inherit the same group as the directory, and newly created subdirectories inherit the set-group-ID bit of the parent directory. On a few systems, a directory’s set-user-ID bit has a similar effect on the ownership of new subfiles and the set-user-ID bits of new subdirectories. These mechanisms let users share files more easily, by lessening the need to use chmod or chown to share new files.