设置 Linux 用户密码过期

设置 Linux 用户密码过期

如何在 Linux 中为用户帐户设置密码过期策略?每个发行版的密码过期策略是否有很大差异?

特别是我使用一些 Debian/Ubuntu 服务器,但显然欢迎链接到其他发行版的适当信息。

[找不到重复的 Q,请告诉我]

答案1

我发布得稍微快一点,看起来 passwd 和 chage 都可以完成您想要完成的任务:

sudo chage [用户名] 将以交互方式允许您设置内容。否则,这里是 chage 和 passwd 的帮助输出。

chage --help 输出:chage --help 用法:chage [选项] [登录]

Options:
  -d, --lastday LAST_DAY        set 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
  -W, --warndays WARN_DAYS      set expiration warning days to WARN_DAYS

命令 passwd --help 的输出

passwd --help
Usage: passwd [options] [LOGIN]

Options:
  -a, --all                     report password status on all accounts
  -d, --delete                  delete the password for the named account
  -e, --expire                  force expire the password for the named account
  -h, --help                    display this help message and exit
  -k, --keep-tokens             change password only if expired
  -i, --inactive INACTIVE       set password inactive after expiration
                                to INACTIVE
  -l, --lock                    lock the named account
  -n, --mindays MIN_DAYS        set minimum number of days before password
                                change to MIN_DAYS
  -q, --quiet                   quiet mode
  -r, --repository REPOSITORY   change password in REPOSITORY repository
  -S, --status                  report password status on the named account
  -u, --unlock                  unlock the named account
  -w, --warndays WARN_DAYS      set expiration warning days to WARN_DAYS
  -x, --maxdays MAX_DAYS        set maximim number of days before password
                                change to MAX_DAYS

答案2

您可以在/etc/login.defs- 具体来说,PASS_MAX_DAYS=、PASS_MIN_DAYS= 和 PASS_WARN_AGE=

您还需要编辑在 /etc/default/useradd 中- INACTIVE= 和 EXPIRE=

这不是完全相同的情况,但这里有更多信息:使不活跃用户帐户过期

相关内容