最後更新: 2020-10-12
目錄
chpasswd
功能:
update passwords in batch mode
用發:
echo "user:pass" | chpasswd
設定 clear-text password 加密方式:
-e, --encrypted
Supplied passwords are in encrypted form.
-c, --crypt-method METHOD
Use the specified method to encrypt the passwords
(Default: /etc/login.defs "ENCRYPT_METHOD SHA512")
/etc/shadow crypt format:
$6$saltsalt$
- "$1$" => MD5
- "$5$" => SHA-1
- "$6$" => SHA-512
mkpasswd
# Centos 沒有此 Package
mkpasswd -m help
mkpasswd -m pw_method PASSWORD SALT
Available methods:
des # standard 56 bit DES-based crypt(3)
md5
sha-256
sha-512
# 建立 sha-512 password
mkpasswd -m sha-512
# 由 string 選出 6 位 pw
makepasswd --chars=6 --count=30 --string=abcdefghijkmnpqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ23456789
pwgen
pwgen [ OPTIONS ] [ pw_length ] [ num_pw ]
OPTIONS
- -1 # Print the generated passwords one per line.
-
-B, --ambiguous # Don't use characters that could be confused by the user when printed
# ('l' and '1', or '0' or 'O') - -c or --capitalize # Include at least one capital letter in the password
Usage exmaple
pwgen -B -c -1
Troubleshoot
Error
chpasswd: cannot lock /etc/passwd; try again later.
<1> 看看 '/' 是否 Full 了
df -h /
<2> 看看 '/etc' 是否 ReadOnly
touch /etc/test.txt
mount -o remount,rw /
<3> 查看有沒有 chpasswd 在行
ps aux | grep chpasswd
<4> 查看是否有 lock file
ls /etc/*.lock
rm /etc/passwd.lock
rm /etc/shadow.lock
rm /etc/group.lock
rm /etc/gshadow.lock