How to Change User Passwords and Lock Passwords with the passwd command on Linux

Published on Aug. 22, 2023, 12:14 p.m.

As a secure and modern operating system, Linux provides passwords. Passwords are used to authenticate users or different entities in order to access some services.

Linux and Unix operating systems stores the passwords in the /etc/shadow file. The users and related information is stored in the /etc/passwd file . The operating system looks at the provided password via the / etc/shadow file.

How to Change User Password

One of the most common operations is changing the user password. Just running the passwd command without any parameter or option changes .

$ passwd

How to Change Another User Password

The passwd command is used to change the current user password. It can also change another user’s password. In order to change another user’s password, we should provide root privileges by using the sudo command .

$ sudo passwd ahmet

How to Change Root Password

You can use the passwd command to change the root password. If we are currently root users, we will run after comman changes the root password.

If we are not root users currently we can use the su command in order to become the root.

$ su
$ passwd

How to Force User Password Reset

Linux password management provides a password change or resets function. When the user is forced for the password reset the next time the user login . The -e option is provided to the passwd command with the user we want . This commands requires the user to change the password in the next login.

$ sudo passwd -e ahmet

How to Lock Password/Account

A user account or password can be locked by providing the user name and -l option.

$ sudo passwd -l ahmet

How to Unlock Password/Account

The -u option is provided to the passwd command. In order to unlock or activate an existing account, one must use it.

$ sudo passwd -u ahmet