linux账号延期,Linux用户密码过期延期

Linux用户默认的用户有效期是永久有效。如果做过了安全加固,用户的有效期通常会设置一个固定的数值,比如90天。

有效期是为了让用户定期修改密码,增加安全性。如果不考虑安全性的问题,在密码即将到期的时候,将密码有效期直接延长下一个90天的话,就需要用一些操作来进行。

1. vim直接修改

记录密码有效期的文件是/etc/shadow,这个是root权限才能进行修改的文件。这个文件中,每一段的含义,请转到:CentOS中/etc/shadow详解

其中,冒号分割的第三段,就是最后一次修改的日期,距离1970年1月1日的天数,我们把这个数值修改为+90的数字,即可延长有效期90天。

2. chage命令修改

帮助信息:

> chage --help

Usage: chage [options] LOGIN

Options:

-d, --lastday LAST_DAY set date of last password change to LAST_DAY

-E, --expiredate EXPIRE_DATE set account expiration date to EXPIRE_DATE

-h, --help display this help message and exit

-I, --inactive INACTIVE set password inactive after expiration

to INACTIVE

-l, --list show account aging information

-m, --mindays MIN_DAYS set minimum number of days before password

change to MIN_DAYS

-M, --maxdays MAX_DAYS set maximim number of days before password

change to MAX_DAYS

-R, --root CHROOT_DIR directory to chroot into

-W, --warndays WARN_DAYS set expiration warning days to WARN_DAYS

重要选项:

-d:修改最后一次修改密码的时间

先查看/etc/shadow文件中,相关用户最后一次修改日期距离1970年1月1日的天数

> sudo grep ^lius /etc/shadow |awk -F: '{print $3}'

18208

(比如18208,+90=18298),然后用chage命令修改这个日期:

chage -d 18291 lius

-l:查看用户账号的各种时间信息

> sudo chage -l lius

Last password change: Feb 06, 2020

Password expires: May 06, 2020

Password inactive: never

Account expires: never

Minimum number of days between password change: 6

Maximum number of days between password change: 90

Number of days of warning before password expires: 30: never

Minimum number of days between password change: 0

Maximum number of days between password change: 99999

Number of days of warning before password expires: 7

这样,Password expires的日期向后延期了90天。

-E:注意,这里的-E是账号过期的时间,不是密码过期的时间,修改的是Account expires这个选项,和我们的预期不符(看上面标红的第二个)。

3. usermod命令

帮助信息:

> sudo usermod --help

Usage: usermod [options] LOGIN

Options:

-c, --comment COMMENT new value of the GECOS field

-d, --home HOME_DIR new home directory for the user account

-e, --expiredate EXPIRE_DATE set account expiration date to EXPIRE_DATE

-f, --inactive INACTIVE set password inactive after expiration

to INACTIVE

-g, --gid GROUP force use GROUP as new primary group

-G, --groups GROUPS new list of supplementary GROUPS

-a, --append append the user to the supplemental GROUPS

mentioned by the -G option without removing

him/her from other groups

-h, --help display this help message and exit

-l, --login NEW_LOGIN new value of the login name

-L, --lock lock the user account

-m, --move-home move contents of the home directory to the

new location (use only with -d)

-o, --non-unique allow using duplicate (non-unique) UID

-p, --password PASSWORD use encrypted password for the new password

-R, --root CHROOT_DIR directory to chroot into

-s, --shell SHELL new login shell for the user account

-u, --uid UID new UID for the user account

-U, --unlock unlock the user account

-v, --add-subuids FIRST-LAST add range of subordinate uids

-V, --del-subuids FIRST-LAST remove range of subordinate uids

-w, --add-subgids FIRST-LAST add range of subordinate gids

-W, --del-subgids FIRST-LAST remove range of subordinate gids

-Z, --selinux-user SEUSER new SELinux user mapping for the user account

相关选项:

-e:这个-e和chage中的-E的功能相同,改变的是账号的过期时间,和需求不符。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值