Linux账户密码过期安全策略设置

Linux账户密码过期安全策略设置、Linux账号密码过期会导致crontab作业不能执行


最近因用oracle用户执行shell脚本做定时备份脚本任务,在执行crontab命令有如下报错:

$ crontab -l
You (oracle) are not allowed to access to (crontab) because of pam configuration.


在网上找了些资料解决方式说明如下:

在Linux系统管理中,有时候需要设置账号密码复杂度(长度)、密码过期策略等,这个主要是由/etc/login.defs参数文件中的一些参数控制的的。它主要用于用户账号限制,里面的参数主要有下面一些:

/etc/login.defs:

# 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_DIRMaildir
MAIL_DIR/var/spool/mail     #新建用户邮件目录
#MAIL_FILE.mail
# Password aging controls:
#
#PASS_MAX_DAYSMaximum number of days a password may be used.
#PASS_MIN_DAYSMinimum number of days allowed between password changes.
#PASS_MIN_LENMinimum acceptable password length.
#PASS_WARN_AGENumber of days warning given before a password expires.
#
PASS_MAX_DAYS30    #密码最大有效期,此处参数PASS_MAX_DAYS为30,表示60天后,密码会过期。99999表示永不过期。
PASS_MIN_DAYS7      #两次修改密码的最小间隔时间,0表示可以随时修改账号密码
PASS_MIN_LEN8         #密码最小长度,对于root无效
PASS_WARN_AGE7     #密码过期前多少天开始提示(过期7天开始提醒)
#
# Min/max values for automatic uid selection in useradd
#
UID_MIN                  1000        #用户ID的最小值(新建用户uid从1000开始)
UID_MAX                 60000       #用户ID的最大值(最大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从1000开始)
GID_MAX                 60000      #组ID最大值(最大为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
USERDEL_CMD        #默认注释状态,如果定义了该变量,表示当删除一个user时,应删除/打印/ cron的工作等所拥有的用户被删除(作为第一个参数传递)。
#
# 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_HOMEyes 
CREATE_HOME        #表示是否创建用户home目录(要不要创建家目录)。
# The permission mask is initialized to this value. If not specified, 
# the permission mask will be initialized to 022.
UMASK           077
UMASK    #权限掩码初始化值(家目录权限)
# This enables userdel to remove user groups if no members exist.
#
USERGROUPS_ENAB yes 
USERGROUPS_ENAB   #该参数启用,表示userdel删除用户时,如果该用户用户组如果没有成员存在,则会删除该用户组(删除用户的时候是否同时删除用户组)
# Use SHA512 to encrypt password.
ENCRYPT_METHOD SHA512     #密码加密规则

修改了/etc/login.defs下参数时,会立即生效,但是它只对修改后创建的用户生效。例如修改了PASS_MAX_DAYS参数等后,我们新建一个用户oracle。

# cat /etc/shadow |grep oracle
oracle:$6$lHwtkVv30/OimAws9fMOG0lTpvrE6vIYGRUQpERYp4yvOLwg6/1EZJF55L81:18397:7:99999:7:::

# cat /etc/passwd |grep oracle
oracle:x:1000:1000::/home/oracle:/bin/bash

image.png

因为CREATE_HOME为yes,所以创建用户test后,就会默认在/home目录下创建oracle目录,这个可以在添加用户的规则文件/etc/default/useradd里面查看或修改

# cat /etc/default/useradd
# useradd defaults file
GROUP=100
HOME=/home     #把用户的主目录建在/home中
INACTIVE=-1    #是否启用帐号过期停权,-1表示不启用
EXPIRE=        #帐号终止日期,不设置表示不启用
SHELL=/bin/bash    #所用SHELL的类型
SKEL=/etc/skel        #默认添加用户的目录默认文件存放位置;也就是说,当我们用adduser添加用户时,用户家目录下的文件,都是从这个目录中复制过去的
CREATE_MAIL_SPOOL=yes


如果此时,假如用户oracle有特殊需求,要求这个账号的密码永不过期,此时就可以使用chage命令来处理(关于chage命令,此处不做展开)

chage -M 99999 oracle

chage1.jpg


猜你喜欢

转载自blog.51cto.com/meiling/2495619