mkpasswd, pwgen 與 chpasswd

最後更新: 2020-10-12

目錄

 


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

 

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