文件夹拥有 suid 权限是什么意思?

Jus*_*ner 3 permissions suid

我知道文件具有 suid 权限意味着什么。这意味着当其他用户对其具有执行权限时,他们以文件的所有者身份执行。但是当文件夹具有 suid 权限时,这意味着什么?我做了一些测试,该文件夹似乎没有什么特别之处。有人可以帮忙解释一下吗?谢谢。

我使用的是 Oracle Linux 7.6。

root:[~]# cat /etc/*release*
Oracle Linux Server release 7.6
NAME="Oracle Linux Server"
VERSION="7.6"
ID="ol"
VARIANT="Server"
VARIANT_ID="server"
VERSION_ID="7.6"
PRETTY_NAME="Oracle Linux Server 7.6"
ANSI_COLOR="0;31"
CPE_NAME="cpe:/o:oracle:linux:7:6:server"
HOME_URL="https://linux.oracle.com/"
BUG_REPORT_URL="https://bugzilla.oracle.com/"

ORACLE_BUGZILLA_PRODUCT="Oracle Linux 7"
ORACLE_BUGZILLA_PRODUCT_VERSION=7.6
ORACLE_SUPPORT_PRODUCT="Oracle Linux"
ORACLE_SUPPORT_PRODUCT_VERSION=7.6
Red Hat Enterprise Linux Server release 7.6 (Maipo)
Oracle Linux Server release 7.6
cpe:/o:oracle:linux:7:6:server
root:[~]#
Run Code Online (Sandbox Code Playgroud)

以下是我在新安装的服务器上的测试。

root:[~]# pwd
/root
root:[~]# ls -lad /root
dr-xr-x---. 9 root root 4096 Aug 16 22:07 /root
root:[~]# mkdir test
root:[~]# ls -lad test
drwxr-xr-x. 2 root root 4096 Aug 16 22:07 test
root:[~]#
root:[~]# useradd a
root:[~]# passwd a
Changing password for user a.
New password:
BAD PASSWORD: The password is a palindrome
Retype new password:
passwd: all authentication tokens updated successfully.
root:[~]# chmod u+s test
root:[~]#
root:[~]# su - a
[a@localhost ~]$ cd /root/test
-bash: cd: /root/test: Permission denied
[a@localhost ~]$ cd /root
-bash: cd: /root: Permission denied
[a@localhost ~]$ logout
root:[~]#
root:[~]# ls -lad /root
dr-xr-x---. 10 root root 4096 Aug 16 22:07 /root
root:[~]# chmod o+x /root
root:[~]#
root:[~]# su - a
Last login: Fri Aug 16 22:08:54 CST 2019 on pts/0
[a@localhost ~]$ cd /root/test
[a@localhost test]$
[a@localhost test]$ pwd
/root/test
[a@localhost test]$ ls -la .
total 8
drwsr-xr-x.  2 root root 4096 Aug 16 22:07 .
dr-xr-x--x. 10 root root 4096 Aug 16 22:07 ..
[a@localhost test]$ touch file1
touch: cannot touch ‘file1’: Permission denied
[a@localhost test]$ logout
root:[~]#
root:[~]# chmod o+w test/
root:[~]#
root:[~]# su - a
Last login: Fri Aug 16 22:09:31 CST 2019 on pts/0
[a@localhost ~]$
[a@localhost ~]$ cd /root/test
[a@localhost test]$ touch file1
[a@localhost test]$ ls -la
total 8
drwsr-xrwx.  2 root root 4096 Aug 16 22:11 .
dr-xr-x--x. 10 root root 4096 Aug 16 22:07 ..
-rw-rw-r--.  1 a    a       0 Aug 16 22:11 file1
[a@localhost test]$ mkdir folder1
[a@localhost test]$ ls -la
total 12
drwsr-xrwx.  3 root root 4096 Aug 16 22:11 .
dr-xr-x--x. 10 root root 4096 Aug 16 22:07 ..
-rw-rw-r--.  1 a    a       0 Aug 16 22:11 file1
drwxrwxr-x.  2 a    a    4096 Aug 16 22:11 folder1
[a@localhost test]$
Run Code Online (Sandbox Code Playgroud)

如您所见,用户a在其中创建的文件和文件夹似乎/root/test并未继承其所有者和组。所有者和组是a和 不是root。我的测试有问题吗?我是 Linux 新手。

小智 6

根据 GNU 手册,这意味着在目录中创建的文件(包括子文件夹)将继承其组和用户:

在一些系统上,目录的 set-user-ID 位对新子文件的所有权和新子目录的 set-user-ID 位具有类似的影响。这些机制通过减少使用 chmod 或 chown 来共享新文件的需要,让用户更容易共享文件。