Summary of practical tips for passwd commands in the CentOS system

Source: Internet
Author: User

This article mainly introduces the Linux system passwd command Practical Tips Summary, is the basic knowledge of Linux primer learning, the need for friends can refer to the following Let 's review the basic usage of the passwd command:

linux passwd command to change the password of the user
syntax
passwd [-K] [-l] [-u [-f]] [-d] [-S] [username]

-d Delete password
-f enforcement
-k update can only be sent after expiration
-l stop account use
Span style= "FONT-SIZE:16PX;" >-s Display password information

-u enable a stopped account
-x Set the validity period of the password
-g Modify the group password
-i Stop user account after expiration
select parameters:
–help Display Help information
instance
Modify user password

# passwd W3cschool//Set W3cschool user's password
Enter new UNIX Password://Enter password, no echo
Retype new UNIX Password://Confirm 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.

OK, let's take a look at the actual application scenario:
Example 1: Changing the password for a system user

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

[email protected] ~]$ passwd
changing password for user Linuxtechi.
changing password for Linuxtechi.
(current) UNIX password:
New Password:
Retype new Password:
Passwd:all authentication Tokens updated successfully.
[email protected] ~]$

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

[email protected] ~]# passwd
[email protected] ~]# passwd Linuxtechi

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

Example 2: Show password status information

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

[email protected] ~]# passwd-s Linuxtechi
Linuxtechi PS 2015-09-20 0 99999 7-1 (Password set, SHA512 crypt.)
[email protected] ~]#

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

Example 3: Show password status information for all accounts

In order to display the status information for all user passwords, you need to use the "-as" option in the passwd command, as shown in the following example:

[email protected]:~# passwd-sa

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

Example 4: Remove a user's password by using the-D option

With my example, delete the ' Linuxtechi ' user's password.

[email protected] ~]# passwd-d Linuxtechi
removing password for user Linuxtechi.
passwd:success
[email protected] ~]#
[email protected] ~]# passwd-s Linuxtechi
Linuxtechi NP 2015-09-20 0 99999 7-1 (Empty password.)
[email protected] ~]#

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

Example 5: Set the password to expire immediately

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

[email protected] ~]# passwd-e Linuxtechi
expiring password for user Linuxtechi.
passwd:success
[email protected] ~]# passwd-s Linuxtechi
Linuxtechi PS 1970-01-01 0 99999 7-1 (Password set, SHA512 crypt.)
[email protected] ~]#

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

Example 6: Lock the System user's password

Using the '-l ' option in the passwd command locks the user's password, and it adds "!" to the beginning of the password. When his/her password is locked, the user will not be able to change its password.

[email protected] ~]# passwd-l Linuxtechi
Locking password for user Linuxtechi.
passwd:success
[email protected] ~]# passwd-s Linuxtechi
Linuxtechi LK 2015-09-20 0 99999 7-1 (Password locked.)
[email protected] ~]#

Example 7: Unlocking a user's password with the-u option

[email protected] ~]# passwd-u Linuxtechi
Unlocking password for user Linuxtechi.
passwd:success
[email protected] ~]#

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

Use the-i option in the passwd command to set the inactivity time of the system user. Users will not be able to log in if the user (I am using a Linuxtechi user) expires after the user has passed ' N ' Days (10 days in my case) without changing their password.

[email protected] ~]# passwd-i Linuxtechi
Adjusting aging data for user Linuxtechi.
passwd:success
[email protected] ~]#
[email protected] ~]# passwd-s Linuxtechi
Linuxtechi PS 2015-09-20 0 99999 7 (Password set, SHA512 crypt.)
[email protected] ~]#

Example 9: Setting the minimum time for password changes using the-N option

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.

[email protected] ~]# passwd-n Linuxtechi
Adjusting aging data for user Linuxtechi.
passwd:success
[email protected] ~]# passwd-s Linuxtechi
Linuxtechi PS 2015-09-20 99999 7 (Password set, SHA512 crypt.)
[email protected] ~]#

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 after n days, his/her password will expire.

[email protected] ~]# passwd-w Linuxtechi
Adjusting aging data for user Linuxtechi.
passwd:success
[email protected] ~]# passwd-s Linuxtechi
Linuxtechi PS 2015-09-20 99999 (Password set, SHA512 crypt.)
[email protected] ~]#

Summary of practical tips for passwd commands in the CentOS system

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.