Note: We have tested the commands described here on Ubuntu 20.04 LTS. However, the same commands also work for other Linux distributions.
- Change User Password through Command Line
- Change Your Own Password
- Change Password for Another User
- Change Root Password
- Force a User To Change Its Passwords
- Change Password through GUI
- Introduction
- How to Change Another User’s Password in Linux
- Change a User’s Password Without a Prompt (Non-Interactive)
- Change Passwords for Multiple Users
- How to Force a User to Change Password at Next Login in Linux
- Locking & Unlocking User Passwords in Linux
- Conclusion
- Change user password in Ubuntu [Command Line]
- Change (or set) the root password in Ubuntu
- Change Ubuntu password using GUI
- More on user passwords in Linux
- Reset Ubuntu password from recovery mode
- Step 1: Boot into recovery mode
- Step 2: Drop to root shell prompt
- Step 3: Remount the root with write access
- Step 4: Reset username or password
- Possible Troubleshoot:
- Alternate method to reset Ubuntu password
- Step 1
- Step 2
- Step 3
- Step 4
- If resetting Ubuntu passwords is this easy, isn’t this a security risk?
- Bonus Tip: Handling the possible keyring issue after changing the password
- Did it help you?
- Prerequisites
- Passwd command Options
- Passwd Command Examples
- Change User Password
- Immediate password expiry
- Check password status for user
- Delete user password
- Set inactive days after the password expiry
- Set minimum days to change the password
- Set warning period before password expiry
- Set maximum days password remains valid
- Lock a user account
- Unlock a user account
- Enable quiet mode
- Change Password in Bash
- Conclusion
- Linux passwd Command
- Selecting Strong Password
- Change Your Own or Current User Password
- Change Another/Different User Password
- Change Password From GUI
- Change Password For GNOME
- Change Password For XFCE
- Force Password Change In Next Login
- Linux User and Password Files
- Introduction
- Temporary Switching to root
- Changing Root Password
- Conclusion
- Without Rebooting
- Reboot Required
- Other Ways
Change User Password through Command Line
Change Your Own Password
To change your own password, simply type the below command without sudo in your terminal window:
$ passwd
After doing so, your password will be changed.
Change Password for Another User
$ sudo passwd <username>
$ sudo password sim
Change Root Password
$ sudo passwd
$ sudo passwd root
First, provide the password for sudo, and then enter the new password that you want to set for the root account.
After doing so, the password of the root account will be changed.
Force a User To Change Its Passwords
$ passwd --expire <username>
$ passwd --expire sim
Change Password through GUI
Step 1: Open Settings application in your system. You can do so right-clicking the desktop and choosing Settings from the appeared menu. Alternatively, you can press the super key and in the search area, type settings. Then from the search results, select the Settings utility.
These commands should work on any Linux distribution, such as Ubuntu, Debian, Linux Mint, CentOS, Rocky Linux, etc.
Introduction
In Linux and Unix-like operating systems, you can change passwords, and related changes, using the passwd
utility. The hashed passwords, along with other related information is stored in the /etc/shadow file. To see the file contents you can go ahead and run:
sudo cat /etc/shadow
It’s very important that you keep a habit of using strong passwords on your machines. This is especially important if your machine is a server that’s exposed to the internet, where bad actors may constantly attempt to break in.
Table of Contents
- Introduction
- How to Change Your User Password in Linux
- How to Change Another User’s Password in Linux
- How to Force a User to Change Password at Next Login in Linux
- Locking & Unlocking User Passwords in Linux
- Conclusion
passwd
You’ll be prompted to enter your current password to make sure it’s really you.
Changing password for edxd. Current password:
Input your current password and press Enter.
Passwords won’t be displayed on the screen when you input them, for security reasons.
If the password you entered is correct, you’ll next you’ll be prompted to type the new password you want to set.
Usually, the minimum requirements for your new password are a minimum length of 6 characters, for the password not to be too simple, and for it not to be too similar to the current password.
We recommend you use a complex password of at least 12 characters, as we mentioned in the intro.
New password:
Next you’ll have to enter the new password again:
Retype new password:
If the password fits the minimum requirements then your password should now be successfully changed, and the next time the system asks it will expect your new password.
passwd: password updated successfully
How to Change Another User’s Password in Linux
sudo passwd bytexd_user
New password: Retype new password: passwd: password updated successfully
passwd: You may not view or modify password information for bytexd_user.
Change a User’s Password Without a Prompt (Non-Interactive)
sudo usermod --password $(openssl passwd -6 '8n&E8MgZd^Rc') bytexd_user
It’s recommended that you put the password in single quotes – '8n&E8MgZd^Rc'
instead of 8n&E8MgZd^Rc
, in order to avoid accidental character substitution if you have characters such as $1
in your password.
Change Passwords for Multiple Users
First we run the command:
sudo chpasswd
edxd:somenewpassword bytexd_user:someothernewpassword stelixd:yetanotherpassword
When you are done press Ctrl+D
for the changes to take effect and return to the regular prompt.
There won’t be any confirmation message in the output.
How to Force a User to Change Password at Next Login in Linux
sudo passwd -e bytexd_user
passwd: password expiry information changed.
ssh [email protected]
You are required to change your password immediately (administrator enforced) Changing password for bytexd_user. Current password: New password: Retype new password: passwd: password updated successfully Connection to 172.141.197.192 closed.
After successfully updating the password, if you’re logging in via SSH, then the connection will close.
Locking & Unlocking User Passwords in Linux
We can do this using passwd -l
.
sudo passwd -l bytexd_user
passwd: password expiry information changed.
[email protected]'s password:
Permission denied, please try again.
sudo passwd -u bytexd_user
passwd: password expiry information changed.
Conclusion
You can view all options for the passwd
command from the manual by running man passwd
in your command line, or by reading the man page online.
If you have any questions or have enountered issues, feel free to leave a comment and we’ll get back to you as soon as we can.
Why do you need to change the password in Ubuntu? Let me give you a couple of scenarios.
- Change user password via the command line
- Change root user password
- Change user password via GUI
Change user password in Ubuntu [Command Line]
If you want to change your current password, simply run this command in a terminal:
passwd
You’ll be asked to enter your current password and the new password twice.
You won’t see anything on the screen while typing the password. This is perfectly normal behavior for UNIX and Linux.
passwd
Sometimes, the passwd
command will throw errors like:
Small Password: If the new password is shorter than 8 characters
Fails Dictionary Check: Does not contain enough different characters. So, use some other characters than just numbers and try again.
sudo passwd <user_name>
If you changed your password and forgot it later, don’t worry. You can easily reset Ubuntu password.
How to Reset Forgotten Ubuntu Password in 2 Minutes
Change (or set) the root password in Ubuntu
You can set or change root password using the passwd command. However, in most cases, you don’t need it and you shouldn’t be doing it.
Now, about changing the root password.
Else, you can change it using the existing root password.
sudo passwd root
Change Ubuntu password using GUI
I have used GNOME desktop with Ubuntu 22.04 here. The steps should be more or less the same for other desktop environments and Ubuntu versions.
Go to Overview (press Windows/Super key) and search for Settings.


Now, select Set password Now option on the dialog box and type and confirm the new password. If you are changing your own password, you’ll also have to enter your current password.

How to Reset Forgotten Ubuntu Password in 2 Minutes
More on user passwords in Linux
Passwd command in Linux: 8 Practical Examples
Here’s a fun thing you can do with sudo so that it makes fun of you when you enter incorrect password.
And get familiar with the Seahorse password manager app in Linux desktops.
Seahorse: Manage Your Passwords & Encryption Keys in Linux
Forgot your Ubuntu login password? It happens.
If you haven’t used Ubuntu for some time, it’s only natural to not remember the password. The good news is that you don’t need to reinstall the entire operating system because of it. You can recover Ubuntu passwords easily.
The method mentioned here works for resetting an Ubuntu password in VMware, dual boot or single install. All you need is a little bit of patience and to run a couple of commands. You’ll reset the root password within minutes.
Forgot Linux Password on WSL? Here’s How to Reset it Easily
Forgot the password of your Linux distribution app you installed in Windows via WSL? No worries. You can easily reset the Linux password in WSL.
Reset Ubuntu password from recovery mode
Step 1: Boot into recovery mode
Switch the computer on. Go to the grub menu. Generally, it appears automatically – if not, then hold down the shift key or press Esc key until the boot menu appears.
If you’re using Oracle VirtualBox or VMware, you have to hold down the shift key when the logo of Oracle or VMware appears.
In the grub menu, select the “Advanced Options for Ubuntu”:

In here, you’ll see the option to go to recovery mode:

It will bring you to a black screen with several lines of output being displayed in a flash. Wait for a few seconds here.
Step 2: Drop to root shell prompt
Now you’ll be presented with different options for recovery mode. Here you need to choose “Root – Drop to root shell prompt“. Just press the enter key to select this option. Like in the picture below:

You’ll see that when you select the root shell prompt option, an option to enter commands appears at the bottom. This is your root shell prompt and this is where you’ll use the commands to reset the password.
Step 3: Remount the root with write access
You need to have write access to the root partition. By default, it has read-only access.
Use the command below to remount it with write access:
mount -rw -o remount /
Step 4: Reset username or password
ls /home
passwd username
It prompts for a new password. Enter the new password twice.
Do note that nothing is displayed on the screen when you start typing the password. This is perfectly normal and actually a security feature in Linux systems. Just blindly type the password and press enter.
Enter new UNIX password:
Retype new UNIX password:
Voilà! There you go. You have just successfully reset the password. Now exit the root shell prompt:
exit
When you exit, you’ll be back at the recovery mode menu. Select the normal boot option here.

There will be a warning about graphics mode compatibility. Don’t worry. A complete reboot will fix any issues with this.
You should now be able to log in with the new password.
Possible Troubleshoot:
While entering the new password you might be prompted with Authentication token manipulation error like this:
mount -rw -o remount /
Now try to reset the password again. It should work now.
As you can see, it is extremely easy to change Ubuntu password even if you’ve forgotten it. It will barely take a few minutes.
Alternate method to reset Ubuntu password
If for some reason you have difficulty dropping to the root shell and changing the password, you can try these steps.
Step 1
Reboot your computer. Hold shift to bring up the grub screen (if it doesn’t appear automatically). Press E at the grub prompt to edit the grub screen.
Step 2
Find the line starting with linux, change the ro to rw and append init=/bin/bash at the end of that line.

Step 3
Press ctrl-x to save your changes and boot.
In other words, your system will boot up to a passwordless root shell.
Step 4
Set your new password.
Once you’ve set the new password, exit the terminal. Just type reboot in the terminal or use the shutdown command.
shutdown -r now
Your password should be changed now.
If resetting Ubuntu passwords is this easy, isn’t this a security risk?
That’s a fair question. One of the main advantages of Linux over Windows is its security. But if “anyone” can reset the password, how come Ubuntu or other Linux distributions can be considered secure?
Let me explain a few things here. The main security risk is if someone hacks into your account from a remote location via the internet. That’s not happening here.
If anyone has physical access to your computer, the data in your computer is already at risk. Unless the entire disk is encrypted, anyone can “steal” your data using a live USB without even entering your installed operating system.
This lack of root password is a deliberate feature The “advanced options for Ubuntu” in the boot menu allow you to perform some specific root-related tasks from the “root shell prompt”. This is why you’re able to reset the Ubuntu password through this method.
Bonus Tip: Handling the possible keyring issue after changing the password
There is a keyring feature in Ubuntu that is used for keeping passwords locked and safe.
When you reset the forgotten password, the keyring remains unlocked and you may see an error message like this.

Open the Passwords and Keys application and here, delete the Login passwords.

When you try to use Google Chrome again in Ubuntu, it will ask you to create a new keyring. Use the new login password as the keyring password.
Did it help you?

I hope I made things clear about resetting forgotten passwords in Ubuntu.
In this tutorial, we’ll be learning about passwd command in Linux to change passwords in Linux.
Prerequisites
- Any Linux system
- Basic knowledge of Linux command line
- An existing user account
- Required privilege to run the command
passwd [option] [user]
The configuration files passwd uses are:
/etc/passwd
— stores the user account information/etc/shadow
— stores secure user account information/etc/pam.d/passwd
— stores PAM configuration for passwd
Passwd command Options
Passwd Command Examples
Change User Password
Type passwd command without any option can change your own password.
$ passwd
To change the root password, type:
sudo passwd root

Immediate password expiry
$ sudo passwd -e werewolf

As we can see, we are provided with the message that the password expiry information changed.
$ su werewolf

Check password status for user

Understanding password status output:
- The user
linuxopsys
has a usable password (P) that is set to expire on02/08/2022
. - The user has to wait minimum
0
days between password changes i.e. can change password without any set interval. - The user has to change his password every
99999
days. - User will be warned
7
days before a required password change. - The number of days after which the user’s account will be disabled following the password expiry is set to
-1
i.e. user account won’t be disabled after the password expiry.
$ sudo passwd -Sa

Delete user password
$ sudo passwd -d werewolf


Set inactive days after the password expiry
$ sudo passwd -i 7 werewolf

You can verify by typing:
$ sudo passwd -S werewolf

Set minimum days to change the password
$ sudo passwd -n 1 werewolf

Set warning period before password expiry
$ sudo passwd -w 5 werewolf

The number of warning days has changed to 5 in the password status:

Set maximum days password remains valid
$ sudo passwd -x 7 werewolf

Confirm by checking:

Lock a user account
$ sudo passwd -l werewolf
Unlock a user account
sudo passwd -u werewolf

Enable quiet mode
$ passwd -q

Change Password in Bash
echo -e "newpassword" | passwd username
Conclusion
In this tutorial, we became familiar with the passwd command which is used to change passwords. We have also covered some of the useful passwd command options with practical examples.
Linux passwd Command
passwd OPTIONS USERNAME
OPTIONS is used to specify different options like delete, expire, inactivate password.
Help and more information about the passwd command can be printed by using the -h
or –help option like below.
$ passwd -h
Selecting Strong Password
!W2i0s2e0tut._
- Use both upper and lower case letters multiple times randomly
- Use digits from 0 to 9 multiple times randomly
- Use special characters and punctuation marks like !,*?#$%;. etc.
- Do not use regular daily words without change
- Make it easy to remember but can not be guessed by others especially attackers
Change Your Own or Current User Password
$ passwd

$ whoami
Change Another/Different User Password
$ sudo passwd ahmet
$ sudo passwd root

$ su -
Password:
#
# passwd
New password:
Retype new password:
passwd: password updated successfully

Change Password From GUI
Change Password For GNOME


Change Password For XFCE


Force Password Change In Next Login
$ sudo passwd --expire ismail
Linux User and Password Files
$ cat /etc/passwd

$ cat /etc/shadow
cat: /etc/shadow: Permission denied
$
$ sudo cat /etc/shadow
Introduction
Temporary Switching to root
sudo command-name
sudo su -
whoami
Output
root
Changing Root Password
sudo passwd root
The new root password will be required to be entered and confirmed.
Make sure you use a strong and unique password when creating the password. The most critical part of your account’s security is having a strong password. A strong password often consists of at least 16 characters, one uppercase letter, one lowercase letter, one number, and one special character.
When you type the password, it does not appear on the screen.
Output
Enter new UNIX password:
Retype new UNIX password:
passwd: password updated successfully
That’s it. The password for the root account has been updated.
You can now use the new password to log in to your Ubuntu system as root.
Conclusion
The root account in Ubuntu has no password by default. To run commands with root capabilities, the sudo command is advised.
You’ll need to set the root password before you can log in as root.
If you have any queries, please leave a comment below and we’ll be happy to respond to them.
Here are a few ways I can think of, from the least intrusive to the most intrusive.
Without Rebooting
With sudo: if you have sudo
permissions to run passwd
, you can do:
sudo passwd root
Enter your password, then enter a new password for root twice. Done.
These are the easy ones.
Reboot Required
- Reboot.
- Enter boot-time password, if any.
- Enter your boot loader’s menu.
- If single user mode is available, select that (Debian calls it ‘Recovery mode’).
- If not, and you run GRUB:
- Highlight your normal boot option.
- Press e to enter edit mode. You may be asked for a GRUB password there.
- Highlight the line starting with
kernel
orlinux
. - Press e.
- Add the word ‘single’ at the end. (don’t forget to prepend a space!)
- Press Enter and boot the edited stanza. Some GRUBs use Ctrl—X, some use b. It says which one it is at the bottom of the screen.
mount / -o remount,rw
passwd # Enter your new password twice at the prompts
mount / -o remount,ro
sync # some people sync multiple times. Do what pleases you.
reboot
and reboot
, or, if you know your normal runlevel, say telinit 2
(or whatever it is).
- Mount the root volume.
- Get
passwd
running. - Change your password with the
passwd
command.
Rescue Disk: this one’s easy. Boot a rescue disk of your choice. Mount your root filesystem. The process depends on how your volumes are layered, but eventually boils down to:
# do some stuff to make your root volume available.
# The rescue disk may, or may not do it automatically.
mkdir /tmp/my-root
mount /dev/$SOME_ROOT_DEV /tmp/my-root
$EDITOR /tmp/my-root/etc/shadow
# Follow the `/etc/shadow` editing instructions near the top
cd /
umount /tmp/my-root
reboot
Other Ways
Obviously, there are countless variations to the above. They all boil down to two steps:
- Get root access to the computer (catch-22 — and the real trick)
- Change root’s password somehow.
I want to change the password I assigned to root on my Debian webserver to something longer and more secure.
How do I do that? I haven’t forgotten/lost the current password, I just want to change it.
Rui F Ribeiro
26 gold badges146 silver badges225 bronze badges
asked Mar 25, 2011 at 14:08
Paul D. WaitePaul D. Waite
5 gold badges21 silver badges21 bronze badges
Ah, use the passwd
program as root:
sudo passwd root
Or, if you’re running as root already (which you shouldn’t be), just:
passwd
answered Mar 25, 2011 at 14:08
Paul D. WaitePaul D. Waite
5 gold badges21 silver badges21 bronze badges
answered Mar 25, 2011 at 20:30
You have to boot in Recovery Mode before using Paul D. Waite’s suggestion:
- Right after booting your Debian system choose «boot in Recovery Mode»
-
Right after booting into «Recovery Mode» right at the command prompt simply
type:sudo password root
then the system will ask for the new Root’s password once and twice to verify and you ARE done.
42 gold badges164 silver badges222 bronze badges
answered Sep 16, 2014 at 5:12
I’m trying to change the password that is asked when running sudo
in Ubuntu. Running sudo passwd
or sudo passwd root
does give me the two new password prompts and it successfully changes the password.
So the root password is changed but not the password for sudo
.
How do I change the sudo
password?
asked Feb 25, 2013 at 18:35
To change it, try plain passwd
, without arguments or running it through sudo
.
Alternately, you can issue:
$ sudo passwd <your username>
answered Feb 25, 2013 at 18:37
The password you use for sudo is the password of your own account, not the root account. sudo
is used to grant you access to commands that need to be executed as root without giving you root access directly. To change your own password, use passwd
without sudo.
answered Feb 25, 2013 at 18:37