Example of the passwd command in 10 Linux

Source: Internet
Author: User
Tags crypt

Example of the passwd command in 10 Linux

As shown in the passwd command name, it is used to change the password of the System user. If the passwd command is executed by a non-root user, it will ask the current user's password and then set the new password of the user who calls the command. When this command is executed by the Super User root, You can reset the password of any user, including the user who does not know the current password.

In this article, we will use an instance to introduce the passwd command.

Syntax:
# passwd {options} {user_name}

You can use different options in the passwd command. The list is as follows:

 

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 ~]$ passwdChanging 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.

  1. [root@linuxworld ~]#passwd
  2. [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.

  1. [root@linuxworld ~]#passwd-S linuxtechi
  2. linuxtechi PS 2015-09-200999997-1(Passwordset, SHA512 crypt.)
  3. [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:

  1. 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.

  1. [root@linuxworld ~]#passwd-d linuxtechi
  2. Removing password for user linuxtechi.
  3. passwd:Success
  4. [root@linuxworld ~]#
  5. [root@linuxworld ~]#passwd-S linuxtechi
  6. linuxtechi NP 2015-09-200999997-1(Empty password.)
  7. [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.

  1. [root@linuxworld ~]#passwd-e linuxtechi
  2. Expiring password for user linuxtechi.
  3. passwd:Success
  4. [root@linuxworld ~]#passwd-S linuxtechi
  5. linuxtechi PS 1970-01-010999997-1(Passwordset, SHA512 crypt.)
  6. [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.

  1. [root@linuxworld ~]#passwd-l linuxtechi
  2. Locking password for user linuxtechi.
  3. passwd:Success
  4. [root@linuxworld ~]#passwd-S linuxtechi
  5. linuxtechi LK 2015-09-200999997-1(Password locked.)
  6. [root@linuxworld ~]#

 

Example 7: Use the-u option to unlock the User Password
  1. [root@linuxworld ~]#passwd-u linuxtechi
  2. Unlocking password for user linuxtechi.
  3. passwd:Success
  4. [root@linuxworld ~]#

 

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

Use the-I option in the passwd command to set the inactivity time of the System user. 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.

  1. [root@linuxworld ~]#passwd-i 10 linuxtechi
  2. Adjusting aging data for user linuxtechi.
  3. passwd:Success
  4. [root@linuxworld ~]#
  5. [root@linuxworld ~]#passwd-S linuxtechi
  6. linuxtechi PS 2015-09-20099999710(Passwordset, SHA512 crypt.)
  7. [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.

  1. [root@linuxworld ~]#passwd-n 90 linuxtechi
  2. Adjusting aging data for user linuxtechi.
  3. passwd:Success
  4. [root@linuxworld ~]#passwd-S linuxtechi
  5. linuxtechi PS 2015-09-209099999710(Passwordset, SHA512 crypt.)
  6. [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.

  1. [root@linuxworld ~]#passwd-w12 linuxtechi
  2. Adjusting aging data for user linuxtechi.
  3. passwd:Success
  4. [root@linuxworld ~]#passwd-S linuxtechi
  5. linuxtechi PS 2015-09-2090999991210(Passwordset, SHA512 crypt.)
  6. [root@linuxworld ~]#

Via: http://www.linuxtechi.com/10-passwd-command-examples-in-linux/

Author: Pradeep Kumar Translator: strugglingyouth Proofreader: wxy

This article was originally compiled by LCTT and launched with the honor of Linux in China

This article permanently updates the link address:

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.