在Linux上关闭密码到期


3

我看到很多文件建议chage在Debian和Ubuntu上使用,但apt-get update && apt-get install chage没有安装该软件包。例如,

root@ubuntu:~/Desktop# apt-get install chage
Reading package lists... Done
Building dependency tree       
Reading state information... Done
E: Unable to locate package chage

我发现我需要编辑/etc/shadow。我到底需要如何编辑root下面的行,这样我的Linux才不会要求我在每次登录时更改密码?

root@ubuntu:~# cat /etc/shadow
root:$6$U.dnAQ2f$FV$/aF23Yn.sq1BYVjinlI9251nAarzqGKES18RxadV5bTakcfCNYAMljUwSaQZYV0r4MttHF0SFO7ebq3E1m/:0:0:99999:7:::

我按照deong建议编辑了根线

root:$6$U.dnAQ2f$FV$/aF23Yn.sq1BYVjinlI9251nAarzqGKES18RxadV5bTakcfCNYAMljUwSaQZYV0r4MttHF0SFO7ebq3E1m/:0:0:::::

它仍然在登录时要求输入密码。

我还按照http://www.lifelinux.com/setting-up-password-aging-in-linux/上的说明进行操作:

root@ubuntu:/home# chage -m 7 -M 60 -W 7 -I 7 root
root@ubuntu:/home# chage -m 0 -M 99999 -I -1 root
root@ubuntu:/home# change -l root
-bash: change: command not found
root@ubuntu:/home# chage -l root
Last password change                                    : password must be changed
Password expires                                        : password must be changed
Password inactive                                       : password must be changed
Account expires                                         : 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 must be changed?我也做了chage -I -1 -m 0 -M 99999 -E -1 root,但是没有帮助。

Answers:


5
$ man 5 shadow

描述该文件的格式。从那里开始,第五个字段是最长密码使用期限。

最长密码使用期限最长密码使用期限是用户必须更改密码的天数。

经过此天数后,密码可能仍然有效。应该要求用户在下次登录时更改其密码。

空字段表示没有最长密码使用期限,没有密码警告期和没有密码闲置期(请参阅下文)。

如果最大密码使用期限小于最小密码使用期限,则用户无法更改其密码。

就您而言,您已经按了触发器,因此还需要摆脱提示,立即在下次登录时更改密码。再次查询手册页...

上次密码更改的日期上次密码更改的日期,表示自1970年1月1日以来的天数。

值0具有特殊含义,即用户下次登录系统时应更改其密码。

空字段表示密码老化功能已禁用。

因此,您还应该从第三个字段中删除零。一旦您禁用了该功能,也不需要第四项。

因此,您应该能够完全删除第五个字段以实现所需的功能。如

root:$6$U.dnAQ2f$FV$/aF23Yn.sq1BYVjinlI9251nAarzqGKES18RxadV5bTakcfCNYAMljUwSaQZYV0r4MttHF0SFO7ebq3E1m/:::::::

就是说,我通常建议不要像这样直接编辑文件,除非您100%确信您知道自己在做什么。

编辑:另外,chage是Ubuntu上passwd软件包的一部分,我以为您已经安装了。


我像您一样编辑了该行,但仍然得到ubuntu login: root Password: You are required to change your password immediately (root enforced) Changing password for root. (current) UNIX password: Enter new UNIX password: Retype new UNIX password:

您知道我是否还需要编辑另一个文件以禁用密码到期吗?

对不起...我读得不够仔细。我已经编辑了答案,以包括更多内容。请注意,所有这些内容都在手册页中明确列出。
— deong 2013年

-2
sudo chage -d -1 root

将关闭密码有效期。


OP已经表明他们无法安装chage。
— Tripleee '18

抱歉 没有一些实用程序,除了直接编辑/ etc / shadow之外,别无其他方法。但是,我的答案会对例如Ubuntu用户(刚刚在Ubuntu 16.04.3 LTS上进行测试)有所帮助。
— ajaaskel '18

AFAIK chage是Ubuntu中的标准配置,无需单独安装。
— ajaaskel '18
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.