mkpasswd, pwgen 與 chpasswd

最後更新: 2015-12-19

目錄

  • chpasswd
  • mkpasswd
  • pwgen

 


chpasswd

# DES, MD5, NONE, and SHA256 or SHA512
# By default, PAM (/etc/pam.d/chpasswd)

-c, --crypt-method METHOD
 

/etc/shadow crypt format:

$6$saltsalt$

"$1$" => MD5
"$5$" => SHA-1
"$6$" => SHA-512

P.S.

On Debian-based systems you can use mkpasswd.

 


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

 

-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')

-N, --num-passwords=num             # Generate num passwords. Default: 8

 

Usage exmaple

pwgen -B -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