Managing user accounts is essential in Linux systems. One of the most critical tasks is managing passwords. The passwd command in Linux is used to update a user’s authentication token or password. It’s a simple but powerful tool. You can use it to change your own password or manage other users’ passwords if you have the necessary permissions.

This guide will show you how to use the passwd command in various scenarios. You’ll learn how to change passwords, force password updates, lock accounts, and more.

Basic Syntax of the passwd Command

Here’s the basic syntax for the passwd command:

passwd [OPTIONS] [USERNAME]
  • USERNAME: The user whose password you want to change. If you omit this, the command will change the password of the user who runs it.
  • OPTIONS: Various options to modify the behavior of the command (we’ll cover these later).

Changing Your Own Password

Changing your password is straightforward. Just type passwd in the terminal and follow the prompts.

passwd

After entering your current password, you’ll be prompted to enter a new one twice. If the passwords match, your password is updated.

Changing password for user your_username.
Current password: 
New password: 
Retype new password: 
passwd: all authentication tokens updated successfully.

Changing Another User’s Password as Root

As a system administrator, you may need to change another user’s password. You must have root privileges to do this.

passwd username

Output:

Enter new UNIX password: 
Retype new UNIX password: 
passwd: password updated successfully.

Replace username with the actual username. The system will prompt you to enter the new password for the user.

Forcing Users to Change Password on Next Login

Sometimes, you need to ensure a user updates their password the next time they log in. Use the -e option to force this.

passwd -e username

This command expires the user’s password immediately. The user must change their password at the next login.

Locking and Unlocking User Accounts

Locking a user account prevents the user from logging in. This is useful if you need to temporarily disable a user’s access.

Locking an account:

passwd -l username

Unlocking an account:

passwd -u username

When you lock an account, an exclamation mark (!) is added in front of the encrypted password in /etc/shadow. Unlocking removes this mark.

Setting Password Expiration and Policies

You can enforce password expiration policies using the passwd command. For example, to set a password to expire after 30 days:

passwd -x 30 username

You can also set the minimum number of days between password changes:

passwd -n 7 username

This command ensures the user cannot change their password more than once in seven days.

Disabling Password for a User Account

In some cases, you may want to allow a user to log in without a password. You can disable the password like this:

passwd -d username

This command removes the password, allowing the user to log in without one. Be cautious with this, as it reduces security.

Conclusion

The passwd command is a vital tool for managing user accounts in Linux. I hope you should now have a solid understanding of how to use the passwd command effectively. Keep your system secure by managing passwords wisely. You can now easy set or reset password on dedicated server hosting from Atlantic.Net!