linux command

passwd

Linux Command – passwd ใช้ในการเปลี่ยน password ของ System user

 

คำสั่ง

1. เปลี่ยน password ของ user ที่ใช้งาน

$ passwd
Changing password for saixiii.
(current) UNIX password:

 

2. เปลี่ยน password ของ user อื่นโดยไม่ทราบ password เก่า

ต้อง login เป็น root

$ sudo passwd staff

 

3. เปลี่ยน password root โดยไม่ทราบ password เก่า

ต้อง boot เข้าสู่ recovery mode ด้วย user root

หากจำเป็นต้อง mount /

mount -rw -o remount /

เปลี่ยน password user

passwd staff

เปลี่ยน password root

passwd

 

โครงสร้างคำสั่ง

 passwd [options] [LOGIN]

 

รายละเอียด

เป็นคำสั่งที่ใช้ในการเปลี่ยน password ของ System user โดยสามารถเปลี่ยนได้เฉพาะ user ที่ทำการ login อยู่เท่านั้น นอกจาก user root สามารถเปลี่ยน password ให้กับทุก user ในระบบได้

 

Option

  -a, --all
 This option can be used only with -S and causes show status for all users.

 -d, --delete
 Delete a user's password (make it empty). This is a quick way to disable a password for an account. It will set the named account passwordless.

 -e, --expire
 Immediately expire an account's password. This in effect can force a user to change his/her password at the user's next login.

 -h, --help
 Display help message and exit.

 -i, --inactive INACTIVE
 This option is used to disable an account after the password has been expired for a number of days. After a user account has had an expired password for INACTIVE days, the user
 may no longer sign on to the account.

 -k, --keep-tokens
 Indicate password change should be performed only for expired authentication tokens (passwords). The user wishes to keep their non-expired tokens as before.

 -l, --lock
 Lock the password of the named account. This option disables a password by changing it to a value which matches no possible encrypted value (it adds a ´!´ at the beginning of
 the password).

 Note that this does not disable the account. The user may still be able to login using another authentication token (e.g. an SSH key). To disable the account, administrators
 should use usermod --expiredate 1 (this set the account's expire date to Jan 2, 1970).

 Users with a locked password are not allowed to change their password.

 -n, --mindays MIN_DAYS
 Set the minimum number of days between password changes to MIN_DAYS. A value of zero for this field indicates that the user may change his/her password at any time.

 -q, --quiet
 Quiet mode.

 -r, --repository REPOSITORY
 change password in REPOSITORY repository

 -R, --root CHROOT_DIR
 Apply changes in the CHROOT_DIR directory and use the configuration files from the CHROOT_DIR directory.

 -S, --status
 Display account status information. The status information consists of 7 fields. The first field is the user's login name. The second field indicates if the user account has a
 locked password (L), has no password (NP), or has a usable password (P). The third field gives the date of the last password change. The next four fields are the minimum age,
 maximum age, warning period, and inactivity period for the password. These ages are expressed in days.

 -u, --unlock
 Unlock the password of the named account. This option re-enables a password by changing the password back to its previous value (to the value before using the -l option).

 -w, --warndays WARN_DAYS
 Set the number of days of warning before a password change is required. The WARN_DAYS option is the number of days prior to the password expiring that a user will be warned
 that his/her password is about to expire.

 -x, --maxdays MAX_DAYS
 Set the maximum number of days a password remains valid. After MAX_DAYS, the password is required to be changed.

 

กลุ่มคำสั่ง

chpasswd(8), passwd(5), shadow(5), usermod(8)

 

Reference:

คำสั่ง Unix – Linux Command

Linux, Unix

 

Author: Suphakit Annoppornchai

Credit: https://saixiii.com

2 Thoughts to “passwd – Linux Command คำสั่งเปลี่ยน password ของ System user”

  1. […] chsh(1), passwd(1), crypt(3), groupadd(8), groupdel(8), groupmod(8), login.defs(5), newusers(8), subgid(5), […]

  2. […] chfn(1), chsh(1), passwd(1), crypt(3), gpasswd(8), groupadd(8), groupdel(8), groupmod(8), login.defs(5), subgid(5), […]

Leave a Reply