How do I change a user password in Ubuntu Linux?

See all Ubuntu Linux related FAQ
We recently switched from Windows server operating system to Ubuntu Linux operating system at work. I am a developer by profession and do not know much about Linux. I need to change the sftp/ssh user account password on Ubuntu. How do I change a user password in Ubuntu Linux?

Introduction – Your Ubuntu Linux account information stored in a file named /etc/passwd and encrypted password hashes in /etc/shadow. This page explains to you how to change the Ubuntu Linux root and user account password using the passwd command line.
Tutorial details
Difficulty level Easy
Root privileges Yes
Requirements Ubuntu Linux
Category User Management
OS compatibility Debian Linux Mint Ubuntu
Est. reading time 4 minutes
Advertisement

How to change a user password in Ubuntu

  1. Open the terminal application by pressing Ctrl+Alt+T
  2. To change a password for user named tom in Ubuntu, type:
    sudo passwd tom
  3. To change a password for root user on Ubuntu Linux, run:
    sudo passwd root
  4. And to change your own password for Ubuntu, execute:
    passwd

How to change a root (superuser) password in Ubuntu

Firstly, open a terminal window. If you want to change the password for remote Ubuntu server, log in using the ssh command:
$ ssh user@ubuntu-server-ip
$ ssh vivek@ubuntu-webserver-1
$ ssh ubuntu@aws-ec2-cloud-server-name

Type ‘sudo -i‘ at the command prompt, and press the Enter key:
$ sudo -i
Type the current user password and press Enter key. Finally, type passwd command and press Enter to change password for root user. For example:
$ passwd

How to change a root user password in Ubuntu Linux

Change password for root user on Ubuntu

Similarly, you can type the following single command on Ubuntu to change the root user password as well:
$ sudo passwd

How do I change the user account password on Ubuntu?

Again open a terminal window. Type the following command to change the password for regular Ubuntu user account named jerry:
$ sudo passwd {userNameHere}
$ sudo passwd jerry ## <-- change password for jerry ##
$ sudo passwd vivek ## <-- change password for vivek ##

How to change a user password in Ubuntu Linux

How to change the user Password in Ubuntu Linux

Deleting a user password

WARNING! Users will not be able to log in when the password is deleted or expired on Ubuntu Linux.
The syntax is as follow to remove the password for the account called tom:
$ sudo passwd -d tom
## OR ##
$ sudo passwd --delete jerry

You will see confirmation on screen as follows:

passwd: password expiry information changed.

Use the grep command or egrep command to verify that password is empty or expired:
$ sudo grep -w '^UserNameHere' /etc/shadow
$ sudo grep -w '^jerry' /etc/shadow

Here is what you will see:

jerry::19431:0:99999:7:::

To set up a new password when deleted, run:
$ sudo passwd tom
Again, verify it:
$ sudo grep -w '^jerry' /etc/shadow
You will see encrypted password hash starting with $6 as follows:

raj:$6$f6drKZX25nNOaLRh$sRkhK34prrz/Q6lL3eA1s4FbNmbP.syfff.v.0SGQt64UmOzBYzJALi7UN.znu0qPPLD2MsE2Ei9BIPS4ebym1:19431:0:99999:7:::

Of course, you can also force expire the password for the named account jerry. Open the terminal and then type the following command:
$ sudo passwd -e jerry
$ sudo passwd --expire jerry

When user login they will be forced to reset their credentials when you use the -e/--expire option:

Account or password is expired, reset your password and try again
New password: 
Retype new password:

Linux locking an account

Here is how to lock the password of the designated account. The following option disables a password by changing it to a value which matches no possible encrypted value. In addition, it adds a “!” at the beginning of the password. The syntax is:
$ sudo passwd -l {username}
$ sudo passwd -l tom

Linux unlocking an account

Unlock the password of the designated account. In other words, you need to use this option to re-enable a password by changing the password back to its previous value, i.e. to the value before using the -l option. The syntax is:
$ sudo passwd -u {username}
$ sudo passwd -u tom

Conclusion

This quick tutorial taught you how to change the Ubuntu Linux root user and other user account password using the passwd command. You must root user to change the password for all other users, however users can change their password without sudo access. For more info see the passwd command help page using the man command/info command or pass the --help option to the passwd command. For instance:
$ man passwd
$ passwd --help
$ man 5 passwd ## and ##
$ man 5 shadow

Here all option for the passwd command:

Options:
  -a, --all                     report password status on all accounts
  -d, --delete                  delete the password for the named account
  -e, --expire                  force expire the password for the named account
  -h, --help                    display this help message and exit
  -k, --keep-tokens             change password only if expired
  -i, --inactive INACTIVE       set password inactive after expiration
                                to INACTIVE
  -l, --lock                    lock the password of the named account
  -n, --mindays MIN_DAYS        set minimum number of days before password
                                change to MIN_DAYS
  -q, --quiet                   quiet mode
  -r, --repository REPOSITORY   change password in REPOSITORY repository
  -R, --root CHROOT_DIR         directory to chroot into
  -S, --status                  report password status on the named account
  -u, --unlock                  unlock the password of the named account
  -w, --warndays WARN_DAYS      set expiration warning days to WARN_DAYS
  -x, --maxdays MAX_DAYS        set maximum number of days before password
                                change to MAX_DAYS

🥺 Was this helpful? Please add a comment to show your appreciation or feedback.

nixCrat Tux Pixel Penguin
Hi! 🤠
I'm Vivek Gite, and I write about Linux, macOS, Unix, IT, programming, infosec, and open source. Subscribe to my RSS feed or email newsletter for updates.

12 comments… add one
  • Tina Nov 19, 2018 @ 20:53

    For your own password:
    passwd
    For root password:
    sudo passwd root

    • Nicole Morales (Nikki) Mar 14, 2021 @ 18:54

      FYI, we don’t set root password on Ubuntu for security reasons. One user will be added to the ‘sudo’ group and that will act as admin user. This ensures safety as root account without password is locked and cannot be used for ssh.

  • Brij Raj Singh May 23, 2021 @ 13:38

    Nice explanation!

  • Jesse May 26, 2021 @ 2:27

    Hiw do I locate a loss – forgot password? Thx Jesse

  • John Stevenson Mar 16, 2022 @ 14:53

    When I try this, it asks me for my old password, which I don’t have.

    • 🛡️ Vivek Gite (Author and Admin) Vivek Gite Mar 16, 2022 @ 18:18

      Enter the password that you used while log into the system.

  • ak Mar 14, 2023 @ 7:04

    best explation

  • Jim Fitton Apr 12, 2023 @ 3:27

    In a Windows PC I am using only the Ubuntu operating system and want to change the PC startup login password and am totally confused.
    Does changing the “Unix password” change the “PC login password” ?
    Thank you,

    Jim

    • 🛡️ Vivek Gite (Author and Admin) Vivek Gite Apr 12, 2023 @ 7:47

      No. If you change Ubuntu login password, it only affects Ubuntu.

  • Maxwell Apr 24, 2023 @ 16:31

    Hi I have a problem, I cannot change the password in both Kali Linux and Ubuntu Desktop after typing the command I cannot type the new password or the old password and nothing is wrong with my keyboard….

  • thiyagi Dec 7, 2023 @ 6:08

    thanks

Leave a Reply

Your email address will not be published. Required fields are marked *

Use HTML <pre>...</pre> for code samples. Your comment will appear only after approval by the site admin.