linux系统中用户的密码是保存在 /etc/shadow 文件中,其中密码字段分为三个部分,用 $
分开。就不见比较好奇,看看密码只怎么组成的。
比如 $1$KyF5u4ME$VnwrCGapy0Xt3q8MFkPQ51
- 1 -- 表示 md5
- KyF5u4ME -- 表示秘钥
- KyF5u4ME$VnwrCGapy0Xt3q8MFkPQ51 -- 表示哈希后的值
验证一下
useradd liuhaolin
# 用户文件
cat /etc/passwd | grep "liuhaolin"
liuhaolin:x:1002:1002::/home/liuhaolin:/bin/bash
# 密码文件
cat /etc/shadow | grep "liuhaolin"
liuhaolin:!!:18620:0:99999:7:::
# 修改用户密码 密码修改为 123456
passwd liuhaolin
Changing password for user liuhaolin.
New password:
BAD PASSWORD: The password is shorter than 8 characters
Retype new password:
passwd: all authentication tokens updated successfully.
# 查看用户状态
passwd -S liuhaolin
liuhaolin PS 2020-12-24 0 99999 7 -1 (Password set, MD5 crypt.)
# 查看新的密码
cat /etc/shadow | grep "liuhaolin"
liuhaolin:$1$KyF5u4ME$VnwrCGapy0Xt3q8MFkPQ51:18620:0:99999:7:::
# 查看加密的方式
authconfig --test | grep hashing
password hashing algorithm is md5
# 查看生成的密码
openssl passwd -1 -salt KyF5u4ME 123456
$1$KyF5u4ME$VnwrCGapy0Xt3q8MFkPQ51
可以看到后的结果都是 $1$KyF5u4ME$VnwrCGapy0Xt3q8MFkPQ51