Linux配置文件详解 login.defs篇

/etc/login.defs文件的来历

/etc/login.defs 是设置用户帐号限制的文件。该文件里的配置对root用户无效。/etc/login.defs 文件用于在Linux创建用户时,对用户的一些基本属性做默认设置,例如指定用户 UID 和 GID 的范围,用户的过期时间,密码的最大长度,等等。

需要注意的是,该文件的用户默认配置对 root 用户无效。并且,当此文件中的配置与 /etc/passwd 和 /etc/shadow 文件中的用户信息有冲突时,系统会以/etc/passwd 和 /etc/shadow 为准。

如果/etc/shadow文件里有相同的选项,则以/etc/shadow里的设置为准,也就是说/etc/shadow的配置优先级高于/etc/login.defs

QQ图片20211125175614.png

各个字段的含义

设置项含义
MAIL_DIR /var/spool/mail

创建用户时,系统会在目录 /var/spool/mail 中创建一个用户邮箱,比如 lamp 用户的邮箱是 /var/spool/mail/lamp

PASS_MAX_DAYS 99999

密码有效期,99999 是自 1970 年 1 月 1 日起密码有效的天数,相当于 273 年,可理解为密码始终有效。

PASS_MIN_DAYS 0

表示自上次修改密码以来,最少隔多少天后用户才能再次修改密码,默认值是 0。 

PASS_MIN_LEN 5

指定密码的最小长度,默认不小于 5 位,但是现在用户登录时验证已经被 PAM 模块取代,所以这个选项并不生效。

PASS_WARN_AGE 7

指定在密码到期前多少天,系统就开始通过用户密码即将到期,默认为 7 天。 

UID_MIN 500

指定最小 UID 为 500,也就是说,添加用户时,默认 UID 从 500 开始。注意,如果手工指定了一个用户的 UID 是 550,那么下一个创建的用户的 UID 就会从 551 开始,哪怕 500~549 之间的 UID 没有使用。

UID_MAX 60000

指定用户最大的 UID 为 60000。

GID_MIN 500

指定最小 GID 为 500,也就是在添加组时,组的 GID 从 500 开始。

GID_MAX 60000

用户 GID 最大为 60000。

CREATE_HOME yes

指定在创建用户时,是否同时创建用户主目录,yes 表示创建,no 则不创建,默认是 yes。

UMASK 077

用户主目录的权限默认设置为 077。

USERGROUPS_ENAB yes

指定删除用户的时候是否同时删除用户组,准备地说,这里指的是删除用户的初始组,此项的默认值为 yes。

ENCRYPT_METHOD SHA512

指定用户密码采用的加密规则,默认采用 SHA512,这是新的密码加密模式,原先的 Linux 只能用 DES 或 MD5 加密。 

[root@localhost ~]# 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
#创建用户时,要在目录/var/spool/mail中创建一个用户mail文件;
MAIL_DIR	/var/spool/mail 
#MAIL_FILE	.mail

# 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.
#用户主目录的权限默认设置为 022
UMASK		022

# 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

# 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为1000,也就是说添加用户时,UID是从1000开始的
UID_MAX                 60000
#最大UID为60000
# System accounts
SYS_UID_MIN               201
SYS_UID_MAX               999

#
# Min/max values for automatic gid selection in groupadd
#
GID_MIN                  1000
#最小用户组ID号
GID_MAX                 60000
#最大用户组ID号
# 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.
#
#创建用户家目录,yes为要求创建,no为不创建
CREATE_HOME	yes

# This enables userdel to remove user groups if no members exist.
#
USERGROUPS_ENAB yes

# Use SHA512 to encrypt password.
#加密模式
ENCRYPT_METHOD SHA512

  

写在最后

以上就是对login.defs文件的基本介绍了,暂时先写这么多,后面也会进行完善。


你知道的越多,你不知道的越多,人才们的 【三连】 就是我创作的最大动力,我们下期见!


注:如果本篇博客有任何错误和建议,欢迎人才们留言,你快说句话啊!

参考:

  1. Linux新建用户配置文件 /etc/login.defs 详解_Linux教程_Linux公社-Linux系统门户网站


#转载请注明出处!
快来制作你的简历吧 ,请猛戳这里→点击在线制作
宝塔服务器面板,一键全能部署及管理,送你3188元礼包。请猛戳这里→点我领取

本文标题:《Linux配置文件详解 login.defs篇》作者:xuanzhe
原文链接:https://blog.xuanzhe.club/?id=58
特别注明外均为原创,转载请注明。

分享到微信

扫描二维码

可在微信查看或分享至朋友圈。

相关文章

发表评论:
验证码

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。

你好,朋友

真是美好的一天!

访客信息

  • IP: 3.141.8.247
  • 地点: United StatesOhioDublin

标签列表

站点信息

  • 文章总数:69
  • 页面总数:2
  • 分类总数:19
  • 标签总数:34
  • 评论总数:7
  • 浏览总数:147010
您好,欢迎到访网站!
忘记密码

网站分类

文章归档

歌曲 - 歌手
0:00