Summary of practical techniques for PASSWD commands in Linux systems

Source: Internet
Author: User
Tags crypt

Let's review the basic usage of the passwd command:

The Linux passwd command is used to change the user's password

Grammar

passwd [-K] [-l] [-u [-f]] [-d] [s] [username]

Necessary parameters:

-D Delete Password

-F Enforcement

-K updates can only be sent after expiration

-L Stop Account usage

-S Display password information

-U enable accounts that have been stopped

-X Set Password expiration

-G Modify Group password

-I stop user account after expiration

Select parameters:

--HELP Display Help information

--version Display version Information

Instance

Modify User Password

The code is as follows:

# passwd W3cschool//Set W3cschool user's password

Enter new UNIX Password://Enter the password with no echo

Retype new UNIX Password://Confirm Password

Passwd:password updated successfully

#

Display account password information

The code is as follows:

# passwd-s W3cschool

W3cschool P 05/13/2010 0 99999 7-1

Delete User Password

The code is as follows:

# passwd-d lx138

Passwd:password expiry information changed.

OK, let's take a look at the actual applications:

Example 1: Changing the password for the system user

When you log on with a non-root user, such as when I log in using ' Linuxtechi ', running the passwd command resets the password for the currently logged-on user.

The code is as follows:

[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 root and run the passwd command, it resets the root password by default and resets the user's password if you specify a username after the passwd command.

The code is as follows:

[Root@linuxworld ~]# passwd

[Root@linuxworld ~]# passwd Linuxtechi

Note: The password for the system user is stored in an encrypted form in the/etc/shadow file.

Example 2: Displaying password status information

To display the status information for a user's password, use the-s option after the passwd command.

The code is as follows:

[Root@linuxworld ~]# passwd-s Linuxtechi

Linuxtechi PS 2015-09-20 0 99999 7-1 (Password set, SHA512 crypt.)

[Root@linuxworld ~]#

In the above output, the first field displays the username, the second field displays the password status (PS = password setting, LK = password lock, NP = no password), the third field shows the time when the password was last modified, and the following four fields show the minimum and maximum periods for which the password can be changed, The warning period and the length of time that the password was not used.

Example 3: Display password status information for all accounts

To display status information for all user passwords, use the "-as" option in the passwd command, as shown in the following example:

The code is as follows:

root@localhost:~# Passwd-sa

(LCTT: Different distributions/passwd behave differently.) CentOS6.6 did not test successfully, but Ubuntu can. )

Example 4: Use the-D option to remove a user's password

Use my example to delete the ' Linuxtechi ' user's password.

The code is as follows:

[Root@linuxworld ~]# passwd-d Linuxtechi

Removing password for user Linuxtechi.

Passwd:success

[Root@linuxworld ~]#

[Root@linuxworld ~]# passwd-s Linuxtechi

Linuxtechi NP 2015-09-20 0 99999 7-1 (Empty password.)

[Root@linuxworld ~]#

The "-d" option clears the user's password and disables user logons.

Example 5: Set Password expiration immediately

Using the '-e ' option in the passwd command causes the user's password to expire immediately, which forces the user to change the password at the next logon.

The code is as follows:

[Root@linuxworld ~]# passwd-e Linuxtechi

Expiring password for user Linuxtechi.

Passwd:success

[Root@linuxworld ~]# passwd-s Linuxtechi

Linuxtechi PS 1970-01-01 0 99999 7-1 (Password set, SHA512 crypt.)

[Root@linuxworld ~]#

Now try to connect to the host with the Linuxtechi user SSH.

Example 6: Lock the System user's password

Use the '-l ' option in the passwd command to lock the user's password, and it will add "!" at the start of the password. When his or her password is locked, the user will not be able to change its password.

The code is as follows:

[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: Unlock user passwords with the-u option

The code is as follows:

[Root@linuxworld ~]# passwd-u Linuxtechi

Unlocking password for user Linuxtechi.

Passwd:success

[Root@linuxworld ~]#

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

Use the-i option in the passwd command to set the inactivity time of the system user. When the user (I am using the Linuxtechi user) password expires, the user passes ' n ' Days (in my case is 10 days) does not change its password, the user will not be able to log in.

The code is as follows:

[Root@linuxworld ~]# passwd-i Linuxtechi

Adjusting aging data for user Linuxtechi.

Passwd:success

[Root@linuxworld ~]#

[Root@linuxworld ~]# passwd-s Linuxtechi

Linuxtechi PS 2015-09-20 0 99999 7 (Password set, SHA512 crypt.)

[Root@linuxworld ~]#

Example 9: Use the-n option to set the minimum time for password changes

In the following example, the Linuxtechi user must change the password within 90 days. 0 means that the user can change its password at any time.

The code is as follows:

[Root@linuxworld ~]# passwd-n Linuxtechi

Adjusting aging data for user Linuxtechi.

Passwd:success

[Root@linuxworld ~]# passwd-s Linuxtechi

Linuxtechi PS 2015-09-20 99999 7 (Password set, SHA512 crypt.)

[Root@linuxworld ~]#

Example 10: Use the-w option to set a 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 after n days, his/her password will expire.

The code is as follows:

[Root@linuxworld ~]# passwd-w Linuxtechi

Adjusting aging data for user Linuxtechi.

Passwd:success

[Root@linuxworld ~]# passwd-s Linuxtechi

Linuxtechi PS 2015-09-20 99999 (Password set, SHA512 crypt.)

[Root@linuxworld ~]#

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.