Linux密码操作

CentOS7 利用Python程序生成sha512加密密码:

[root@localhost ~]# python -c 'import crypt,getpass;pw="zxcvbnm";print(crypt.crypt(pw))'
$6$QCipUn09yISB2Vt1$fq2Tad0xcHng/8rjXG5P8T0NjCw5XuqvEuNZGFGl9Ibk3MM6bqKkMkQztdySSbsdcmynTOtwKAZLSU/KMttbu0

CentOS8 生成sha512加密密码:

[root@localhost ~]# openssl passwd -6 zxcvbnm

linux随机生成一组密码:

[root@localhost ~]# cat /dev/urandom | tr -dc '[:alnum:]' | head -c12
VX8qoAZC3eTn
[root@localhost ~]# cat /dev/urandom | tr -dc '[:alnum:]' | head -c12
nIFtxv6qDmWN
[root@localhost ~]# cat /dev/urandom | tr -dc '[:alnum:]' | head -c12
9djm5P6IfGFP

修改用户密码策略:

chage可以修改用户密码策略

选项:

  • -l:列出用户的详细密码状态;
  • -d 日期:修改 /etc/shadow 文件中指定用户密码信息的第 3 个字段,也就是最后一次修改密码的日期,格式为 YYYY-MM-DD;
  • -m 天数:修改密码最短保留的天数,也就是 /etc/shadow 文件中的第 4 个字段;
  • -M 天数:修改密码的有效期,也就是 /etc/shadow 文件中的第 5 个字段;
  • -W 天数:修改密码到期前的警告天数,也就是 /etc/shadow 文件中的第 6 个字段;
  • -i 天数:修改密码过期后的宽限天数,也就是 /etc/shadow 文件中的第 7 个字段;
  • -E 日期:修改账号失效日期,格式为 YYYY-MM-DD,也就是 /etc/shadow 文件中的第 8 个字段。
查看用户密码状态:
[root@localhost ~]# chage -l yc
Last password change					: never
Password expires					: never
Password inactive					: never
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
修改用户密码策略:
[root@localhost ~]# chage yc
Changing the aging information for yc
Enter the new value, or press ENTER for the default

	Minimum Password Age [0]: 3
	Maximum Password Age [99999]: 42
	Last Password Change (YYYY-MM-DD) [-1]: 2021-10-20
	Password Expiration Warning [7]: 10
	Password Inactive [-1]: 20
	Account Expiration Date (YYYY-MM-DD) [-1]: 2022-10-20

[root@localhost ~]# chage -m 3 -M 42 -W 14 -I 7 -E 2021-10-20 yc

查看修改后的用户密码策略:
[root@localhost ~]# chage -l yc
Last password change					: Oct 20, 2021
Password expires					: Dec 01, 2021
Password inactive					: Dec 08, 2021
Account expires						: Oct 20, 2021
Minimum number of days between password change		: 3
Maximum number of days between password change		: 42
Number of days of warning before password expires	: 14

设置下一次登录强制重设密码:

[root@localhost ~]# chage -d 0 yc
通过chage命令设置此账号密码创建的日期为 1970 年 1 月 1 日(0 就表示这一天),这样用户登陆后就必须修改密码

linux修改用户密码

注:centos
[root@localhost ~]# echo 12345 | passwd --stdin yc
Changing password for user yc.
passwd: all authentication tokens updated successfully.
注:ubuntu
[root@localhost ~]# echo yc:123456 | chpasswd
posted @ 2021-10-18 22:08  咚咚小孩  阅读(189)  评论(0)    收藏  举报