Master the Linux ‘passwd’ Command: A Comprehensive Guide

Peter Hou
3 min readJun 5, 2023

--

This article deeply explores the Linux passwd command. It delves into the command's history, explains when and why to use it, and provides a detailed guide on how to use it with examples. It also outlines some of the tricks associated with the command, points to note, and concludes with a succinct summary of the passwd command.

Instructions

This article dives deep into the Linux passwd command. It explores its history, explains when and why to use it, and provides a detailed guide on how to use it with examples. It also outlines some of the tricks associated with the command, points to note, and concludes with a succinct summary of the passwd command.

History

The passwd command has been a part of Unix/Linux systems for several decades, serving as a crucial tool for managing user passwords.

When and why to use it

You would use the passwd command when you need to change a user's password. This command is particularly useful for system administrators managing user accounts and access control.

How to use it

The passwd command can be used without any arguments to change the password of the current user.

$ passwd
Changing password for user.
(current) UNIX password:
Enter new UNIX password:
Retype new UNIX password:
passwd: all authentication tokens updated successfully.

The commonly used parameters

The passwd command has some commonly used parameters:

  • -l This parameter locks the specified account.
$ sudo passwd -l user
Locking password for user.
passwd: Success
  • -u This parameter unlocks the specified account.
$ sudo passwd -u user
Unlocking password for user.
passwd: Success

Other supported parameters

The passwd command supports many other parameters, including:

  • -d — Delete the password for the specified user account.
  • -e — Expire the password for the specified user account.
  • -f — Force password change on the specified user account.
  • -S — Display password status of the specified user account.

Most common use cases

A common use case for the passwd command is to quickly change the password of the current user or a specified user on the system.

$ sudo passwd user
Enter new UNIX password:
Retype new UNIX password:
passwd: password updated successfully.

The tricky skills

One lesser-known usage of the passwd command is in combination with the -S option, which displays the password status of a user. This is particularly useful for system administrators who need to manage user accounts.

$ sudo passwd -S user
user P 05/31/2023 0 99999 7 -1

What needs to be noted

When using the passwd command, note that it alters information in the /etc/passwd and /etc/shadow files. If these files are altered or tampered with, the output and functionality of the passwd command will be affected accordingly.

Conclusion

The passwd command is a simple but powerful tool that provides valuable functionality for managing user passwords on a Linux system. Understanding its usage and the information it provides is essential for managing user identities and access control.

--

--

Peter Hou
Peter Hou

Written by Peter Hou

I am a Senior Software Engineer and tech lead in a top tech company.

No responses yet