根帐户的 UID/GID 是否始终为 0?

根帐户的 UID/GID 是否始终为 0?

在我管理的所有 Linux 系统上,root 帐户的 GID 和 UID 都是 0。这能保证吗,或者系统是否有可能为 root 提供不同的 ID?

答案1

其实两部分回答你的问题。

Linux 上的超级用户帐户的 uid/gid 是否始终为 0/0?

是的。正如指出的那样里奇·霍莫尔卡一条评论内核中有代码在需要检查 root 用户时明确检查 uid 0,这意味着 root 始终至少具有用户ID0。

uid 为 0 的用户账户名是否始终是root

不。 root只是一个名称,列在 /etc/passwd 或其他身份验证存储中。您也可以将该帐户称为admin,操作系统本身不会在意,但有些应用程序可能不太喜欢它,因为它们希望存在一个名为 的特权帐户root。在 *nix 上调用 uid 0 帐户root是一种非常严格的惯例,但系统并不要求这样做(尽管某些用户空间软件可能需要这样做,可能包括系统管理实用程序)。

还值得注意的是,正如西蒙·里希特在 BSD 上,经常存在第二uid 0 帐户,按照惯例命名toor(即“root”的反向拼写,并且从词汇上讲 root按字母顺序排列的列表中)。例如,FreeBSD 使用它为 root 用户提供自定义的 shell 设置,而 root 用户则使用默认 shell保证它存在于系统的根分区上(对于恢复目的很有用)。

答案2

1) 管理员的 uid 始终为 == 0。这是在内核中编码的。需要在内核中进行一些编码才能更改这一点。这没什么意义,所以没有完成。例如,对于共享同一 NFS 的其他 unix 来说,这将是不一致的。

2) uid 0 不一定映射到 root。最好的例子是 FreeBSD。它有两个 uid == 0 帐户,区别在于 shell。root 有 shell /bin/sh,这是一个简单的 shell,当您的磁盘坏了并且您需要 fsck /usr 时很有用。toor 使用 tcsh,它在非紧急情况下更有用,因为它有历史记录等内容。

另一个更个人化的例子;我曾经做过一份工作,他们在 NIS 上有一个 root equiv(即 uid=0)帐户。密码为空!因为新系统管理员记不住机器上的 root 密码。我为此大喊大叫,原因很明显(NIS 密码按定义无法隐藏其空白)。我对这个帐户很不满意。

而且实际上并不是系统赋予 uid 0 为 root 权限,而是你。你可以使用 passwd 文件或其他命名目录 (NIS、ldap) 更改此权限,但这些权限并未编译进去。不过你应该在 /etc/passwd 中至少有一个 uid 0 帐户,因为当你真正需要网络时,你可能没有网络。

因此 root 始终是 uid 0,但 uid 0 不一定始终是 root。

答案3

对于使用 nonStop 服务器的系统,ROOT_UID 不是 0 而是 65535。

OSS 用户和组 OSS 环境不提供常见的 UNIX 默认用户名和用户 ID,除非站点管理员明确创建它们。但是,确实存在等效的 OSS 用户名和用户 ID。例如,对于 OSS 用户 ID (UID) 65535(超级 ID),即用户 SUPER.SUPER 及其别名,存在通常与 UNIX 用户名 root 和用户 ID 0 相关联的权限。

https://h20195.www2.hpe.com/V2/GetPDF.aspx/4AA4-6316ENW.pdf

在coreutils中,你可以找到root-uid.h头文件:

/* The user ID that always has appropriate privileges in the POSIX sense.

   Copyright 2012-2016 Free Software Foundation, Inc.

   This program is free software: you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation; either version 3 of the License, or
   (at your option) any later version.

   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.

   You should have received a copy of the GNU General Public License
   along with this program.  If not, see <http://www.gnu.org/licenses/>.

   Written by Paul Eggert.  */

#ifndef ROOT_UID_H_
#define ROOT_UID_H_

/* The user ID that always has appropriate privileges in the POSIX sense.  */
#ifdef __TANDEM
# define ROOT_UID 65535
#else
# define ROOT_UID 0
#endif

#endif

答案4

/* The user ID that always has appropriate privileges in the POSIX sense.

   Copyright 2012-2016 Free Software Foundation, Inc.

   This program is free software: you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation; either version 3 of the License, or
   (at your option) any later version.

   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.

   You should have received a copy of the GNU General Public License
   along with this program.  If not, see <http://www.gnu.org/licenses/>.

   Written by Paul Eggert.  */

#ifndef ROOT_UID_H_
#define ROOT_UID_H_

/* The user ID that always has appropriate privileges in the POSIX sense.  */
#ifdef __TANDEM
# define ROOT_UID 65535
#else
# define ROOT_UID 0
#endif

#endif

相关内容