Dit deel is nog niet vertaald. Je ziet de Engelse tekst.
Wat het doet
chpasswd reads lines in the form USER:PASSWORD and sets each password, hashed with the method of /etc/login.defs (SHA-512 or yescrypt). It is the standard way to set passwords in scripts, Kickstart %post sections and provisioning tools, because it works the same on every Linux. With -e the passwords are already hashes.
Zo schrijf je het
chpasswd [OPTION]...
echo 'USER:PASSWORD' | chpasswdOpties 7
Meest gebruikt
Options
Niets past bij dit filter.
Voorbeelden 10
$ als gewone gebruiker# als root (of met sudo)
1Set one password in one line
echo 'mia:RedHat-2026' | chpasswd2Set many passwords from a file
cat newpasswords.txt mia:Start-2026-a leo:Start-2026-b sara:Start-2026-c chpasswd < newpasswords.txt shred -u newpasswords.txtRemove the clear-text file at once.
3Create users and set passwords in a loop
4Force a password change at the first login
5Use a prepared hash (no clear text on the server)
6Choose the hash method
echo 'leo:Long-Passphrase-2026' | chpasswd -c SHA5127Set the root password inside a mounted system
echo 'root:Recovery-2026' | chpasswd -R /mnt/sysroot8Random passwords for a list of users, saved for hand-over
9Check that the password was set
10Kickstart %post example
cat ks-post.txt %post echo 'admin:Change-me-2026' | chpasswd chage -d 0 admin %end
Niets past bij dit filter.
Let op
- Passwords typed on the command line land in the shell history. Use a file with rights
600, orchpasswd -ewith a hash. pwqualityrules are not checked bychpasswdwhen root runs it.
Bestanden
/etc/shadow- Where the hashes are stored.
/etc/login.defsENCRYPT_METHOD(default hash method).
Tips om te onthouden
chpasswdis the safe replacement forpasswd --stdinin scripts: it works on every distribution.
Exitcodes
0 | Success. |
1 | Error (unknown user, bad line, no rights). |