我找不到 Ubuntu 20.04 上 0002 umask 的设置位置

我找不到 Ubuntu 20.04 上 0002 umask 的设置位置

我的用户帐户具有非标准 umask 设置 0002,我找不到设置该设置的配置文件。我已使用 在 /etc 和 ~/.bash* 中搜索sudo grep -iIr umask。通过 ssh 在 bash shell 中运行 umask 显示 0002,通过 root shell 运行它su - root显示 0022。

答案1

在 Ubuntu 18.04 LTS 中,umask 0002普通用户的默认设置。

它在 中有定义/etc/login.defs,但是定义分为两部分。

首先,该UMASK设置确定了 root 和普通用户的初始 umask。请注意,注释表明后面的USERGROUPS_ENAB设置将针对普通用户进行修改:

# Login configuration initializations:
#
#       ERASECHAR       Terminal ERASE character ('\010' = backspace).
#       KILLCHAR        Terminal KILL character ('\025' = CTRL/U).
#       UMASK           Default "umask" value.
#
# The ERASECHAR and KILLCHAR are used only on System V machines.
# 
# UMASK is the default umask value for pam_umask and is used by
# useradd and newusers to set the mode of the new home directories.
# 022 is the "historical" value in Debian for UMASK
# 027, or even 077, could be considered better for privacy
# There is no One True Answer here : each sysadmin must make up his/her
# mind.
#
# If USERGROUPS_ENAB is set to "yes", that will modify this UMASK default value
# for private user groups, i. e. the uid is the same as gid, and username is
# the same as the primary group name: for these, the user permissions will be
# used as group permissions, e. g. 022 will become 002.
#
# Prefix these values with "0" to get octal, "0x" to get hexadecimal.
#
ERASECHAR       0177
KILLCHAR        025
UMASK           022

稍后,在同一个文件中:

# Enable setting of the umask group bits to be the same as owner bits
# (examples: 022 -> 002, 077 -> 007) for non-root users, if the uid is
# the same as gid, and username is the same as the primary group name.
#
# If set to yes, userdel will remove the user's group if it contains no
# more members, and useradd will create by default a group with the name
# of the user.
#
USERGROUPS_ENAB yes

Debian 11 具有完全相同的设置,因此 Ubuntu 20.04 可能也有相同的设置。(我目前手边没有 Ubuntu 20.04 VM 可供检查。)

传统上,系统中的所有用户都共享一个主要组(通常名为users)并具有默认的 umask 0022- 或者也许0077系统需要强化的安全态势。

这使得小组项目有些尴尬:一旦系统管理员为项目创建了一个组并将相关用户添加到其中,在操作任何旨在由特定组访问的文件或目录之前,用户必须总是记得使用newgrpsg,否则任何新的或复制的文件将无法被其他组成员写入,这很烦人。

(如果意外地将非组可写文件放在组可写目录中,则另一个组成员用户将能够重命名问题文件并复制它,只要第二个用户可以读取该文件即可。由于第二个用户将是新副本的所有者,他们现在可以将新副本放在有问题的原始副本所在的位置,并调整其权限以允许组项目继续进行,即使意外将项目文件设为非组可写的人也是如此……但根据我的经验,大多数用户都不知道这一点,并向忙碌的系统管理员寻求帮助。)

因此,用户组方案已开发。它包含两个部分:

  1. 对于每个普通用户,还会分配一个组,以便 UID = GID。其他用户不会被分配到该组。
  2. 根据所需的安全态势,普通用户的默认 umask 将被更改为0002或。0007

现在,当一个新的组项目开始时,系统管理员仍然需要创建一个组并为该组分配工作区:

groupadd project
for user in user1 user2 user3; do usermod -a -G project $user; done
mkdir -p /shared/project
chgrp project /shared/project
chmod 2770 /shared/project   # results in permissions drwxrws--- 

现在,用户不需要记住任何特殊的事情,就可以让/shared/project其他组成员完全访问他们创建的文件:它就是有效的。

项目顶级目录上的 setgid 位会导致所有新文件和目录都分配给项目组,项目成员创建的所有目录也将继承 setgid 位。由于用户的 umask 已经允许组写访问,因此默认情况下权限对于组工作来说是正确的。

当用户在其主目录中操作其私人文件时,启用组访问的 umask 不会造成任何问题,因为每个用户都有自己的主要组(UID = GID),该组没有其他成员

相关内容