الفلاتر
طريقة البحث
  • الكلمات العادية تجد الأسماء والنصوص والأمثلة.
  • "كلمتان" تجد العبارة بالضبط.
  • --name أو -x تجد خيارًا.
  • #كلمة تبحث داخل الأوامر فقط.
  • @grep تجد الدروس والمعامل التي تستخدم grep.
  • الفلاتر: cat:network · in:labs · level:rhcsa · ch:8 · root:yes. ضع ! قبل كلمة لاستبعادها. OR بين الكلمات تعني إحداها.
  • ↑ ↓ للتنقل · Enter للفتح · Esc للإغلاق · / للبحث

chpasswd

Set the passwords of many users at once, from lines user:password on standard input.

المستوى
لينكس اليومي
المجموعة
المستخدمون والمجموعات
يحتاج root
نعم
الحزمة
shadow-utils

هذا الجزء لم يُترجم بعد. أنت ترى النص الإنجليزي.

ماذا يفعل

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.

طريقة الكتابة

chpasswd [OPTION]...
echo 'USER:PASSWORD' | chpasswd

الخيارات 7

الأكثر استخدامًا

Options

-e, --encrypted
The passwords are already hashed; store them as they are.
-c, --crypt-method METHOD
Hash method: SHA512, SHA256, YESCRYPT, MD5, DES, NONE.
-s, --sha-rounds ROUNDS
Number of rounds for SHA methods.
-m, --md5
Use MD5 (old, do not use).
-R, --root DIR
Work on the files under DIR (a chroot).
-P, --prefix DIR
Use the files under DIR without chroot.
-h, --help
Show help.

أمثلة 10

$ مستخدم عادي# بصلاحية root (أو مع sudo)

  1. 1Set one password in one line

    echo 'mia:RedHat-2026' | chpasswd
  2. 2Set 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.txt

    Remove the clear-text file at once.

  3. 3Create users and set passwords in a loop

    for u in mia leo sara; do useradd "$u"; echo "$u:Welcome-$RANDOM" | chpasswd; done
  4. 4Force a password change at the first login

    echo 'mia:Temp-2026' | chpasswd
    chage -d 0 mia
  5. 5Use a prepared hash (no clear text on the server)

    openssl passwd -6 'S3cret-2026'
    $6$Tz8...$Qw...
    echo 'mia:$6$Tz8...$Qw...' | chpasswd -e
  6. 6Choose the hash method

    echo 'leo:Long-Passphrase-2026' | chpasswd -c SHA512
  7. 7Set the root password inside a mounted system

    echo 'root:Recovery-2026' | chpasswd -R /mnt/sysroot
  8. 8Random passwords for a list of users, saved for hand-over

    for u in mia leo; do p=$(openssl rand -base64 12); echo "$u:$p" | chpasswd; echo "$u $p" >> /root/handover.txt; done
    chmod 600 /root/handover.txt
  9. 9Check that the password was set

    grep '^mia:' /etc/shadow | cut -d: -f1,2 | cut -c1-20
    passwd -S mia
  10. 10Kickstart %post example

    cat ks-post.txt
    %post
    echo 'admin:Change-me-2026' | chpasswd
    chage -d 0 admin
    %end

انتبه

  • Passwords typed on the command line land in the shell history. Use a file with rights 600, or chpasswd -e with a hash.
  • pwquality rules are not checked by chpasswd when root runs it.

الملفات

/etc/shadow
Where the hashes are stored.
/etc/login.defs
ENCRYPT_METHOD (default hash method).

نصائح للحفظ

  • chpasswd is the safe replacement for passwd --stdin in scripts: it works on every distribution.

رموز الخروج

0Success.
1Error (unknown user, bad line, no rights).

الدليل الكامل

هذه الصفحة تشرح الأمر بكلمات بسيطة. الدليل الأصلي فيه كل التفاصيل.

في الطرفية: man 8 chpasswd