How do I change a user password in Ubuntu Linux?

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 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
Est. reading time 2 minutes

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

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

How to change a root user password in Ubuntu Linux

Change password for root user on Ubuntu

Similarly, you can type the following 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 the user Password in Ubuntu Linux

Deleting a user password

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.

To set up a new password when deleted, run:
sudo passwd -d tom
We 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

sudo passwd -l {username}
sudo passwd -l tom

Linux unlocking an account

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 passwd help page:
man passwd


🐧 Get the latest tutorials on Linux, Open Source & DevOps via RSS feed or Weekly email newsletter.

🐧 5 comments so far... add one


CategoryList of Unix and Linux commands
Disk space analyzersdf ncdu pydf
File Managementcat cp mkdir tree
FirewallAlpine Awall CentOS 8 OpenSUSE RHEL 8 Ubuntu 16.04 Ubuntu 18.04 Ubuntu 20.04
Network UtilitiesNetHogs dig host ip nmap
OpenVPNCentOS 7 CentOS 8 Debian 10 Debian 8/9 Ubuntu 18.04 Ubuntu 20.04
Package Managerapk apt
Processes Managementbg chroot cron disown fg jobs killall kill pidof pstree pwdx time
Searchinggrep whereis which
User Informationgroups id lastcomm last lid/libuser-lid logname members users whoami who w
WireGuard VPNAlpine CentOS 8 Debian 10 Firewall Ubuntu 20.04
5 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

Leave a Reply

Your email address will not be published.

Use HTML <pre>...</pre> for code samples. Still have questions? Post it on our forum