Summary of practical skills for passwd commands in CentOS

Source: Internet
Author: User
Tags crypt
This article mainly introduces the practical tips of passwd commands in Linux. it is the basic knowledge in Linux beginners. if you need it, let's take a look at the basic usage of passwd commands: the Linuxpasswd command is used to change the user's password syntax passwd [-k] [-l] [-u [-f] [-d] [-S] [username] required parameters this article this section describes the practical tips for passwd commands in Linux, it is the basic knowledge for getting started with Linux. if you need it, you can refer to the following to review the basic usage of the passwd command:

The Linux passwd command is used to change the user's password.
Syntax
Passwd [-k] [-l] [-u [-f] [-d] [-S] [username]
Required parameters:
-D. delete the password.
-F force execution
-K updates can only be sent after expiration
-L stop account use
-S: Display password information
-U: enable an account that has been stopped
-X: Set the password validity period.
-G: change the group password.
-I: stops the user account after it expires.
Select parameters:
-Help: displays help information.
-Version: displays version information.
Instance
Change user password

# Passwd w3cschool // Set the password of the w3cschool user
Enter new UNIX password: // Enter the new password. the entered password is not displayed.
Retype new UNIX password: // confirm the password
Passwd: password updated successfully
#

Show account password information

# Passwd-S w3cschool
W3cschool P 05/13/2010 0 99999 7-1

Delete user password

# Passwd-d lx138
Passwd: password expiry information changed.

 

Okay. let's take a look at the actual application scenarios:
Example 1: change the password of a system user

When you use a non-root user to log on, for example, if I use 'linuxtechi' to log on, running the passwd command will reset the password of the currently logged on user.

[Linuxtechi @ linuxworld ~] $ Passwd
Changing password for user linuxtechi.
Changing password for linuxtechi.
(Current) UNIX password:
New password:
Retype new password:
Passwd: all authentication tokens updated successfully.
[Linuxtechi @ linuxworld ~] $

When you log on as the root user and run the passwd command, it will reset the root password by default. if you specify the user name after the passwd command, it resets the password of the user.

[Root @ linuxworld ~] # Passwd
[Root @ linuxworld ~] # Passwd linuxtechi

Note: the password of the system user is encrypted and stored in the/etc/shadow file.

Example 2: Display the password status

To display the status of the user password, use the-S option after the passwd command.

[Root @ linuxworld ~] # Passwd-S linuxtechi
Linuxtechi PS 0 99999 7-1 (Password set, SHA512 crypt .)
[Root @ linuxworld ~] #

In the above output, the user name is displayed in the first field, and the password status is displayed in the second field (PS = password settings, LK = password locked, NP = no password ), the third field shows the time when the password was last modified. the last four fields show the minimum and maximum periods, warning periods, and periods when the password was not used.

Example 3: Display the password status of all accounts

To display the status information of all user passwords, use the "-aS" option in the passwd command, for example:

Root @ localhost :~ # Passwd-Sa

(LCTT note: different releases/passwd have different behaviors. CentOS6.6 is not tested successfully, but Ubuntu can .)

Example 4: use the-d option to delete a user's password

For example, delete the password of the 'linuxtechi' user.

[Root @ linuxworld ~] # Passwd-d linuxtechi
Removing password for user linuxtechi.
Passwd: Success
[Root @ linuxworld ~] #
[Root @ linuxworld ~] # Passwd-S linuxtechi
Linuxtechi NP 0 99999 7-1 (Empty password .)
[Root @ linuxworld ~] #

The "-d" option clears the user password and disables user logon.

Example 5: Set the password to expire immediately

Using the '-E' option in the passwd command will immediately expire the user's password, which will force the user to change the password upon next login.

[Root @ linuxworld ~] # Passwd-e linuxtechi
Expiring password for user linuxtechi.
Passwd: Success
[Root @ linuxworld ~] # Passwd-S linuxtechi
Linuxtechi PS 0 99999 7-1 (Password set, SHA512 crypt .)
[Root @ linuxworld ~] #

Now try to use linuxtechi user SSH to connect to the host.

Example 6: Lock the password of the system user

Use the '-L' option in the passwd command to lock the user's password. it will add "!" to the start position of the password. When his/her password is locked, the user cannot change its password.

[Root @ linuxworld ~] # Passwd-l linuxtechi
Locking password for user linuxtechi.
Passwd: Success
[Root @ linuxworld ~] # Passwd-S linuxtechi
Linuxtechi LK 2015-09-20 0 99999 7-1 (Password locked .)
[Root @ linuxworld ~] #

Example 7: use the-u option to unlock the user password

[Root @ linuxworld ~] # Passwd-u linuxtechi
Unlocking password for user linuxtechi.
Passwd: Success
[Root @ linuxworld ~] #

Example 8: use the-I option to set the inactive time

Use the-I option in the passwd command to set the system user's inactivity time. After the password of the user (I am using linuxtechi user) expires, the user does not change the password after 'n' days (in my case, it is 10 days, you cannot log on.

[Root @ linuxworld ~] # Passwd-I 10 linuxtechi
Adjusting aging data for user linuxtechi.
Passwd: Success
[Root @ linuxworld ~] #
[Root @ linuxworld ~] # Passwd-S linuxtechi
Linuxtechi PS 0 99999 7 10 (Password set, SHA512 crypt .)
[Root @ linuxworld ~] #

Example 9: use the-n option to set the shortest time for password change

In the following example, you must change the password of linuxtechi within 90 days. 0 indicates that you can change the password at any time.

[Root @ linuxworld ~] # Passwd-n 90 linuxtechi
Adjusting aging data for user linuxtechi.
Passwd: Success
[Root @ linuxworld ~] # Passwd-S linuxtechi
Linuxtechi PS 90 99999 7 10 (Password set, SHA512 crypt .)
[Root @ linuxworld ~] #

Example 10: use the-w option to set the warning period before the password expires.

The '-W' option is used in the passwd command to set the user's warning period. This means that his/her password will expire in n days.

[Root @ linuxworld ~] # Passwd-w 12 linuxtechi
Adjusting aging data for user linuxtechi.
Passwd: Success
[Root @ linuxworld ~] # Passwd-S linuxtechi
Linuxtechi PS 90 99999 12 10 (Password set, SHA512 crypt .)
[Root @ linuxworld ~] #
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.