Red Hat Training

A Red Hat training course is available for RHEL 8

26.8. 为新创建的主目录设置默认权限

您可以通过修改 /etc/login.defs 文件来更改新创建的用户的主目录的权限模式。

流程

  1. root 用户身份,在编辑器中打开 /etc/login.defs 文件。
  2. 修改以下部分来设置新的默认 HOME_MODE

    # HOME_MODE is used by useradd(8) and newusers(8) to set the mode for new
    # home directories.
    # If HOME_MODE is not set, the value of UMASK is used to create the mode.
    HOME_MODE       0700

    将默认的八进制值(0700)替换为另一个八进制值。所选模式将用于为主目录创建权限。

  3. 如果设置了 HOME_MODE,请保存更改并退出编辑器。
  4. 如果没有设置 HOME_MODE,请修改 UMASK 来为新创建的主目录设置模式:

    # Default initial "umask" value used by login(1) on non-PAM enabled systems.
    # Default "umask" value for pam_umask(8) on PAM enabled systems.
    # UMASK is also used by useradd(8) and newusers(8) to set the mode for new
    # home directories if HOME_MODE is not set.
    # 022 is the default value, but 027, or even 077, could be considered
    # for increased privacy. There is no One True Answer here: each sysadmin
    # must make up their mind.
    
    UMASK           022

    将默认的八进制值(022)替换为另一个八进制值。如需了解更多详细信息,请参阅 用户文件创建模式掩码

  5. 保存更改并退出编辑器。