3

正如标题所说,任何类 Unix 系统是否将含义赋予目录上的 SUID 位,如果是,它是什么意思?

SVTX(保存的文本或粘性)位有一个含义——除非您可以写入文件,否则您不得从此目录中删除文件。例如,它用于 /tmp。

SGID(设置 GID)位有一个含义——在该目录中创建的文件应属于拥有该目录的组(尽管稍后可以通过显式调用 chown(2) 来更改该分配)。

SUID 位呢?

4

4 回答 4

6

作为 Node 回答的后续,我将从 FreeBSD 手册页中为 mount(8) 发布以下内容:

             suiddir
                 A directory on the mounted file system will respond to
                 the SUID bit being set, by setting the owner of any new
                 files to be the same as the owner of the directory.  New
                 directories will inherit the bit from their parents.
                 Execute bits are removed from the file, and it will not
                 be given to root.

                 This feature is designed for use on fileservers serving
                 PC users via ftp, SAMBA, or netatalk.  It provides secu-
                 rity holes for shell users and as such should not be used
                 on shell machines, especially on home directories.  This
                 option requires the SUIDDIR option in the kernel to work.
                 Only UFS file systems support this option.  See chmod(2)
                 for more information.

以及引用 suid 位的 chmod(2) 手册页部分:

           4000    (the setuid bit).  Executable files with this bit set will
               run with effective uid set to the uid of the file owner.
               Directories with this bit set will force all files and sub-
               directories created in them to be owned by the directory
               owner and not by the uid of the creating process, if the
               underlying file system supports this feature: see chmod(2)
               and the suiddir option to mount(8).

请注意,这是一个安全风险,并且在 FreeBSD 中启用它时知道您在做什么,但我相信 Linux 也需要启用特殊的挂载标志,并且会改变该目录中文件的行为方式。

于 2009-03-09T20:36:03.533 回答
4

从这里复制:

在大多数系统上,如果设置了目录的 set-group-ID 位,则新创建的子文件会继承与目录相同的组,而新创建的子目录会继承父目录的 set-group-ID 位。在少数系统上,目录的 set-user-ID 位对新子文件的所有权和新子目录的 set-user-ID 位有类似的影响。这些机制通过减少使用 chmod 或 chown 共享新文件的需要,让用户更轻松地共享文件。

这些便利机制依赖于目录的 set-user-ID 和 set-group-ID 位。如果像 chmod 和 mkdir 这样的命令会定期清除目录上的这些位,那么这些机制会不太方便,并且共享文件会更加困难。因此,像 chmod 这样的命令不会影响目录的 set-user-ID 或 set-group-ID 位,除非用户以符号模式特别提及它们,或者将它们设置为数字模式。

于 2009-03-09T20:28:20.413 回答
1

当在一个目录上设置时,在这个目录中创建的所有文件和目录都将与 SUID 目录本身具有相同的所有者,无论文件是谁创建的。这是一个不经常使用的功能,但在某些情况下它可能很有用。(来源

更新:我刚刚在 Linux 2.6.25.5-1.1-default #1 SMP x86_64 GNU/Linux openSUSE 11.0 (X86-64) 上试过这个。

mkdir tmp
chmod 4777 tmp
su othergroup
touch testfile

它没有效果。

于 2009-03-09T20:26:32.853 回答
0

SUID 位表明,在执行文件时(当可执行时),进程将以所述文件所有者的身份运行,而不是执行它的用户。

在某些情况下,实用程序是“suid root”以允许权限提升。

编辑:误读原始问题(指的是目录而不是文件) - 出于教育目的保留答案不变;-)

于 2009-03-09T20:25:45.040 回答