计算机网络/计算机科学与应用/系统/运维/开发

用户的相关配置文件


/etc/login.defs文件

配置文件/etc/login.defs用来定义创建用户账号时的默认设置

比如指定用户UID和GID的范围、账号的过期时间和是否需要创建用户家目录等


查看 /etc/login.defs 文件

[root@iZ8vb9nmgwljcf9m2wxaekZ ~]# cat /etc/login.defs
#
# Please note that the parameters in this configuration file control the
# behavior of the tools from the shadow-utils component. None of these
# tools uses the PAM mechanism, and the utilities that use PAM (such as the
# passwd command) should therefore be configured elsewhere. Refer to
# /etc/pam.d/system-auth for more information.
#
# *REQUIRED*
#   Directory where mailboxes reside, _or_ name of file, relative to the
#   home directory.  If you _do_ define both, MAIL_DIR takes precedence.
#   QMAIL_DIR is for Qmail
#
#QMAIL_DIR      Maildir
MAIL_DIR        /var/spool/mail
#MAIL_FILE      .mail
# Password aging controls:
#
#       PASS_MAX_DAYS   Maximum number of days a password may be used.
#       PASS_MIN_DAYS   Minimum number of days allowed between password changes.
#       PASS_MIN_LEN    Minimum acceptable password length.
#       PASS_WARN_AGE   Number of days warning given before a password expires.
#
PASS_MAX_DAYS   99999
PASS_MIN_DAYS   0
PASS_MIN_LEN    5
PASS_WARN_AGE   7
#
# Min/max values for automatic uid selection in useradd
#
UID_MIN                  1000
UID_MAX                 60000
# System accounts
SYS_UID_MIN               201
SYS_UID_MAX               999
#
# Min/max values for automatic gid selection in groupadd
#
GID_MIN                  1000
GID_MAX                 60000
# System accounts
SYS_GID_MIN               201
SYS_GID_MAX               999
#
# If defined, this command is run when removing a user.
# It should remove any at/cron/print jobs etc. owned by
# the user to be removed (passed as the first argument).
#
#USERDEL_CMD    /usr/sbin/userdel_local
#
# If useradd should create home directories for users by default
# On RH systems, we do. This option is overridden with the -m flag on
# useradd command line.
#
CREATE_HOME     yes
# The permission mask is initialized to this value. If not specified, 
# the permission mask will be initialized to 022.
UMASK           077
# This enables userdel to remove user groups if no members exist.
#
USERGROUPS_ENAB yes
# Use SHA512 to encrypt password.
ENCRYPT_METHOD SHA512
#
# Please note that the parameters in this configuration file control the
# behavior of the tools from the shadow-utils component. None of these
# tools uses the PAM mechanism, and the utilities that use PAM (such as the
# passwd command) should therefore be configured elsewhere. Refer to
# /etc/pam.d/system-auth for more information.
#
# *REQUIRED*
#   Directory where mailboxes reside, _or_ name of file, relative to the
#   home directory.  If you _do_ define both, MAIL_DIR takes precedence.
#   QMAIL_DIR is for Qmail
#
#QMAIL_DIR      Maildir
MAIL_DIR        /var/spool/mail
#MAIL_FILE      .mail
# Password aging controls:
#
#       PASS_MAX_DAYS   Maximum number of days a password may be used.
#       PASS_MIN_DAYS   Minimum number of days allowed between password changes.
#       PASS_MIN_LEN    Minimum acceptable password length.
#       PASS_WARN_AGE   Number of days warning given before a password expires.
#
PASS_MAX_DAYS   99999
PASS_MIN_DAYS   0
PASS_MIN_LEN    5
PASS_WARN_AGE   7
#
# Min/max values for automatic uid selection in useradd
#
UID_MIN                  1000
UID_MAX                 60000
# System accounts
SYS_UID_MIN               201
SYS_UID_MAX               999
#
# Min/max values for automatic gid selection in groupadd
#
GID_MIN                  1000
GID_MAX                 60000
# System accounts
SYS_GID_MIN               201
SYS_GID_MAX               999
#
# If defined, this command is run when removing a user.
# It should remove any at/cron/print jobs etc. owned by
# the user to be removed (passed as the first argument).
#
#USERDEL_CMD    /usr/sbin/userdel_local
#
# If useradd should create home directories for users by default
# On RH systems, we do. This option is overridden with the -m flag on
# useradd command line.
#
CREATE_HOME     yes
# The permission mask is initialized to this value. If not specified, 
# the permission mask will be initialized to 022.
UMASK           077
# This enables userdel to remove user groups if no members exist.
#
USERGROUPS_ENAB yes
# Use SHA512 to encrypt password.
ENCRYPT_METHOD SHA512


参数说明:

image.png

USERGROUPS_ENAB yes  : 这行指定的是使用命令 userdel 删除用户时,是否删除用户的初始组,默认是删除。

ENCRYPT_METHOD SHA512:指定 Linux 用户的密码使用 SHA512 散列模式加密,这是新的密码加密模式,原先的 Linux只能用 DES 或 MD5 方式加密


注意:修改该文件中的设置,只针对新创建的用户有效。

例如,限制用户的密码有效期(最大天数)为30天,可以将“PASS_MAX_DAYS”的值设为30,

那么在修改完该配置文件之后,所有新创建用户的密码有效期将是30天。


/etc/skel目录

在创建完用户之后,Linux系统会自动在用户的家目录中产生一些默认的文件,这些文件大多是隐藏的


实例:查看 user2用户家目录默认文件

[root@iZ8vb9nmgwljcf9m2wxaekZ ~]# ls -a /home/user2
.  ..  .bash_logout  .bash_profile  .bashrc


这些文件可以用于设置用户的运行环境,或者用于设置用户登录或退出时自动执行某些操作

例如“.bash_profile”和“.bashrc”文件用于设置用户登录时自动执行某些操作,

“.bash_logout”文件则用于设置用户退出系统时自动执行某些操作


/etc/skel目录为所有的这些默认文件提供了模板,如果在/etc/skel目录中建立目录或放入文件,

那么所有新创建的用户的家目录中就会有这些目录及文件。

如果修改该目录中的用户配置文件、登录脚本等内容,那么新建用户的用户配置文件、登录脚本也会采用修改后的内容。






/etc/login.defs /etc/skel

若无人替你披荆斩棘,那就独自前行栉风沐雨。

评论

^