Change Another User's Password

date: 2023-01-17

For many users of Linux, they are the only person using their machine. In multi-user systems, sometimes a user forgets their password and it needs to be reset by the administrator.

On one of the web servers that I administer, a programmer could log in using a saved password but couldn't view what that password was. There is now a need for him to be able to type the password while logged in, which he can't do if he doesn't know it.


The passwd program allows you to change your own password... if you know your current password. However, you can run passwd as root to change the passwd of any user on the system without knowing their current password. This is exactly what is needed if the user forgot their password.

Elevate to the root user with:


Then typing the root password. Or if you are a member of the sudo group, you can run:

sudo -s

Then type your own password to get to a root shell.

To change a user's password:

passwd jeremy

Where "jeremy" is the username who's password needs to be changed. The passwd program with ask you to type the new password in twice to make sure that you've spelled it as intended. It won't ask for the current password of the user because you are running passwd as root.

Getting the new password to the user

If this computer is able to be logged into on a network (almost always), you'll want to make sure that you communicate the new password to the user in a secure manner so that someone else doesn't intercept the password and login as them. This is especially important if this user is a member of the sudo group, as then a compromised password could allow an unauthorized user to gain root priviliges on the machine.

In my case, I sent the password to the user using encrypted email with the Thunderbird email program. That's a topic for another day.

tags: #linux #sysadmin