← 返回命令列表

Linux command

chpasswd 命令

安全

涉及管道、覆盖或删除,执行前请先确认路径和参数。

常用示例

Example

printf "[username]:[new_password]" | sudo chpasswd

Example

printf "[username_1]:[password_1]\n[username_2]:[password_2]" | sudo chpasswd

Example

printf "[username]:[encrypted_password]" | sudo chpasswd -e

Example

printf "[username]:[new_password]" | sudo chpasswd -c [SHA512]

说明

chpasswd reads username:password pairs from standard input and updates user passwords in batch. This is useful for system administration tasks requiring password changes for multiple users at once, such as during initial account provisioning or automated password rotation. Input format is one user per line as username:password with no spaces around the colon. Passwords are encrypted using the system default method (typically SHA-512) unless a different method is specified. Pre-encrypted passwords can also be supplied with the -e flag.

参数

-e, --encrypted
Passwords are supplied in encrypted form
-c, --crypt-method _method_
Specify encryption method (NONE, DES, MD5, SHA256, SHA512)
-m, --md5
Use MD5 encryption
-s, --sha-rounds _rounds_
Number of rounds for SHA encryption

FAQ

What is the chpasswd command used for?

chpasswd reads username:password pairs from standard input and updates user passwords in batch. This is useful for system administration tasks requiring password changes for multiple users at once, such as during initial account provisioning or automated password rotation. Input format is one user per line as username:password with no spaces around the colon. Passwords are encrypted using the system default method (typically SHA-512) unless a different method is specified. Pre-encrypted passwords can also be supplied with the -e flag.

How do I run a basic chpasswd example?

Run `printf "[username]:[new_password]" | sudo chpasswd` in a terminal, then adjust file names, paths, flags, or remote targets for your system.

What does -e, --encrypted do in chpasswd?

Passwords are supplied in encrypted form