How To Linux Set or Change User Password

How do I set or change Linux system password for any user account? How can I change user password on Linux operating system using the command-line options?

Both Linux and UNIX-like operating systems use the passwd command to change user password. The passwd is used to update a user’s authentication token (password) stored in /etc/shadow file. The passwd change passwords for user and group accounts. A normal user may only change the password for his/her own account, the super user (or root) may change the password for any account. The administrator of a group may change the password for the group. passwd also changes account information, such as the full name of the user, user login shell, or password expiry date and interval.

Linux Set User Password

Type following passwd command to change your own password:
$ passwd
Sample Outputs:

Changing password for vivek
(current) UNIX password:
Enter new UNIX password:
Retype new UNIX password:
passwd: password updated successfully

The user is first prompted for his/her old password if one is present. This password is then encrypted and compared against the stored password. The user has only one chance to enter the correct password. The super user is permitted to bypass this step so that forgotten passwords may be changed. A new password is tested for complexity. As a general guideline, passwords should consist of 10 to 20 characters including one or more from each of following sets:

  1. Lower case alphabetics
  2. Upper case alphabetics
  3. Digits 0 thru 9
  4. Punctuation marks/spacial characters

Linux change password for other user account

You need to login as the root user, type the following command to change password for user vivek:
# passwd vivek
$ sudo passwd vivek
Sample putput:

Enter new UNIX password:
Retype new UNIX password:
passwd: password updated successfully


  • vivek – is username or account name.

Passwords do not display to the screen when you enter them. For example:

Linux Change User Password

Linux changing user password using passwd

Linux Change Group Password

When the -g option is used, the password for the named group is changed. In this example, change password for group sales:
# passwd -g sales
The current group password is not prompted for. The -r option is used with the -g option to remove the current password from the named group. This allows group access to all members. The -R option is used with the -g option to restrict the named group for all users.

Changing user passwords on Linux

As a Linux system administrator (sysadmin) you can change password for any users on your server. To change a password on behalf of a user:

  1. First sign on or “su” or “sudo” to the “root” account on Linux, run: sudo -i
  2. Then type, passwd tom to change a password for tom user
  3. The system will prompt you to enter a password twice

To change or set a new root (superuser) password type:
$ sudo passwd

Forcing Linux user to change password at their next login

By default, Linux passwords never expire for users. However, we can force users to change their password the next time they log in via GUI or CLI methods. The syntax is straightforward:
$ sudo passwd -e {username}
$ sudo passwd --expire {username}

Let us immediately expire an account’s password:
$ sudo passwd -e marlena
The system will confirm it:

passwd: password expiry information changed.

When user try to login via ssh command, they will see the following on screen:

$ ssh marlena@
Last login: Fri Dec  4 04:12:48 2020 from
WARNING: Your password has expired.
You must change your password now and login again!
Changing password for marlena.
Current password: 
New password: 
Retype new password: 
passwd: password updated successfully
Connection to closed.

Locking and Unlocking user password of the named account

Note that the following local command does not disable the account. The user may still be able to login using another authentication token, such as an SSH key. To disable the account, administrators should use either usermod --expiredate 1 {username} or sudo passwd --expire {username} command. Also, users with a locked password are not allowed to change their password to get around the security policy set by sysadmin.

We can lock the password as follows:
$ sudo passwd -l {username}
This option disables a password by changing it to a value which matches no possible encrypted value (it adds a ! at the beginning of the password in the /etc/shadow file. Want to unlock the password, try:
$ sudo passwd -u {username}
The above command option re-enables a password by changing the password back to its previous value. In other words, to the value before using the -l option.

A note about setting up a secure Linux password

Compromises in password security typically result from careless password selection. Avoid common password such as:

  1. Words which appears in a dictionary
  2. Your first and last name
  3. Pet names
  4. Kids or spouses names
  5. License number
  6. Date of birth (DoB)
  7. Home or office address

I strongly recommend that you generate a unique password for all user accounts using your chosen password manager.


The passwd command line utility is used to update or change user’s password. The encrypted password is stored in /etc/shadow file and account information is in /etc/passwd file. To see all user account try grep command or cat command as follows:
$ cat /etc/passwd
$ grep '^userNameHere' /etc/passwd
$ grep '^tom' /etc/passwd

The guidance given in this quick tutorial should work with any Linux distribution, including Alpine, Arch, Ubuntu, Debian, RHEL, Fedora, Oracle CentOS, SUSE/OpenSUSE and other popular Linux distros.

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

🐧 72 comments so far... add one

CategoryList of Unix and Linux commands
Disk space analyzersncdu pydf
File Managementcat
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
72 comments… add one
  • bambi Apr 24, 2007 @ 7:22

    Could you help me how to edit the commands before booting in CentOS? I can’t seem to get it right.
    choose the desired OS, in this case CentOS then press e for edit then select the kernel then press e again and type space linuxsingle then enter to accept changes, press b for boot. They told me that a prompt will appear but there is none so that i can type passwd to change the password and username. Pls. help me.

    • ivonne saucedo Jan 29, 2012 @ 16:38

      i want to change my user password on my laptop the one i use to log in

  • Rick Feb 12, 2008 @ 3:02

    thanks this help alot

  • Aloka Feb 3, 2009 @ 7:52

    I am Aloka . I am student of computer science & I have linux on my machine.
    i forgotten the username & password of it.
    can u help me for this for changing the username & password.
    plz help me.

    • ajit Oct 12, 2010 @ 8:05

      fist open the window than Alt+Ctrl+f1 after that login passwd and type use name and password

      • niono Nov 30, 2010 @ 3:31

        I have done the Alt + CTRL + F1, because I’m new user to LINUX how can I know User and the login password?
        I just want to know password for whenever i click on the network, i have to enter a password to continue the next command. n I don’t understand why it kept prompt the command to enter the pass. thanks

        • john Jan 27, 2016 @ 14:08

          It doesn’t show you typing in the password. You just type it in correctly and press ENTER

    • mansoorali Feb 24, 2011 @ 9:50

      useradd u1
      passwd u1

  • Andy Feb 17, 2009 @ 3:19

    Go to linux rescue mode (single user mode) at the boot prompt when the linux image is loaded and reset your password through the prompt.

  • Chloe May 7, 2009 @ 20:19

    Hey, i want to set my password so that when my linux laptop starts up, my account name comes up and i have to type my password in so that others cannot access my account settings without my password. Help me please!? x

    • shiv Jan 11, 2014 @ 18:16

      hi aloka,
      to see the all user name use following command to see all user entries
      tail /etc/passwd and to see passwords use tail /etc/shadow but password encrypted by using MD5 algorithms if you know cryptography and MD5 algorith then you can get your password and also log in as a root and use command
      passwd also u can get ur password

  • Atta May 28, 2009 @ 21:54


    As a root user I want to reset lost of passwords and want to set each users password with a single command i.e. not have to be asked to type passwords afterwords. So the command needs to include the new password and not require the old one.

    Help would be greatly appreciated

  • Varun Sep 10, 2009 @ 8:02

    How can I change the root password while I’m only a user of it? Please reply me, as fast as can be.

  • AeSix Sep 11, 2009 @ 4:50

    Varun use sudo su
    use your user pass
    then run passwd
    if your user account dont have privlages enough to run as su, your sol.

  • UnixOS Sep 12, 2009 @ 11:24

    AeSix, Don’t you know how can I get or reset password of another user if i am user with limited privilages?! help please….

  • abbakus Oct 8, 2009 @ 17:54

    how can i set an UNSECURE password? During installation process i’m able to set an unsecure password, but it isn’t possible once the system is installed. I know it’s a bad
    practice, but i really need to do it.



    • -Pablo- Jun 28, 2010 @ 14:39

      Try logging in as root or using $ sudo passwd username
      There you can set whichever password you want, which might not be the case when you run the passwd command as a user.

  • deepak mishra Nov 16, 2009 @ 8:39

    i ,m forget passwd then i can do

    • shiv Jan 11, 2014 @ 18:19

      if u r using personal computer then login as root and change the user password like
      or inform ur administrator(root/superuser) as soon

  • Talib Nov 18, 2009 @ 10:09

    I am using Cant OS 5.2 with DC & BDC, pls advise if any tool available to monitor it easily from nework.

  • lokesh Dec 5, 2009 @ 5:20

    hello,can u help me out to find out hw to change the passwd wen previous passwd has been forgotten ??????? u have suggested somebody to go to the rescue mode what dose it mean ,plz describe whole procedure in detail! thanks in anticipation!~

  • Charlie Seah Kam Fei Jan 28, 2010 @ 9:26

    is there anyway to READ the password of user instead of reset it if I have root access?

    • centos7-adm Mar 12, 2016 @ 17:17

      @Charlie Seah Kam Fei , short answer, NO.

  • Charlie Jan 28, 2010 @ 9:27

    Any files in Linux support that? Thanks in advance

  • G.Shoba Jun 12, 2010 @ 16:49

    I want to know how to know d previos password of d super user…how can it be done??
    or change d password of d superuser without having to know d previous one…is dis possible??
    Any help will be greately appritiated…

  • Aamir Ali Jul 1, 2010 @ 15:42

    Helpful. Thanks.

  • aisha Aug 10, 2010 @ 23:31

    when it says type unix password it doesnt let me type what can i do

    • -Pablo- Aug 11, 2010 @ 0:30

      It doesn’t show you a caret but just type ahead. Unix terminals work like that when asking for passwords. Supposedly it’s intended to prevent those looking over your shoulder from seeing how long your password is.

      • aisha Aug 11, 2010 @ 16:54

        thank you that helped

  • steve Aug 31, 2010 @ 11:12

    i have created 70 users in Ubuntu using following shell script,

    for i in $(seq 1 70)
    useradd -d/home/te$i -m te$i

    Now i want to set default password say “xyz” to all 70 users (te1 to te70).
    How can I do so?
    thnx in advance

    • NinjaSysadmin Jun 22, 2011 @ 14:06

      for i in $(seq 1 70)
      useradd -d/home/te$i -m te$i
      echo $i:xyz | chpasswd
      chage -d 0 $i

      Notice the echo line? You should also set the line after, which tells users to change their password when they login. You can remove this if you wish.

  • dr nandinee Oct 31, 2010 @ 19:59

    I m dr nandinee in maharastra forgoten my password plz help me

    • karthi Jan 31, 2011 @ 7:55

      hello nandini which flavour r u using…..

      • DR. HYDE Jul 1, 2011 @ 8:37

        Hi Karthi, It’s not important what flavor to use…
        The good flavor comes from the questioner, I need to add your flavor…
        Can you please contact me for the purpose of cooking you in order to extract your flavor?

  • madhusudhana T Jun 13, 2011 @ 9:01

    set the password by using passwd command how to do in shell scripting

  • Balaviswanathan Jul 5, 2011 @ 11:49


    Thanks for the information. Could you please help me how to create virtual screens like tty/8 ty/9 etc.

    Thanks in advance

  • satti Jul 8, 2011 @ 13:48

    I am satish. I am student of computer science & I have linux on my machine.
    i forgotten the username & password of it.
    can u help me for this for changing the username & password.
    plz help me.

  • sravn Aug 4, 2011 @ 6:30

    i forgot the forgot to enter into my linux os…. can u help me how to reset it….

  • Ramesh Adapwar Dec 23, 2011 @ 10:11

    How a user is able to change his own password /etc/shadow file when he doesn’t have even read permission on it?

  • steven Mar 29, 2012 @ 17:19

    im lock out of my laptop and i forget the password any suggestions?

  • sachin May 30, 2012 @ 8:10

    Dear sir,
    How to configure password should not contain user’s name / user id in redhat5

  • Paresh Aug 6, 2012 @ 15:15

    if normal user can’t read /etc/shadow file then how will they reset own password.

  • Gelo Aug 7, 2012 @ 9:56

    do any version of linux support this?

  • Gelo Aug 7, 2012 @ 9:59

    is it the same on all version of linux?

  • Boyd Oct 22, 2012 @ 14:34

    i need a script that can change ALL Redhat Linux (CentOS) email accounts at once to one password.

  • vaibhav kanchan Dec 5, 2012 @ 7:11

    Which file should I check in centos5 or rhel 5 for commenting out the password history so that I can keep on continuing using same password to login to the server?

  • ranga santhosh Apr 15, 2013 @ 4:08

    ya its very nice……….. and easy to understand

  • ABUMON Sep 14, 2013 @ 4:34

    How can be changing your password in LINUX

    • R Carrick Nov 30, 2014 @ 21:03

      You need to be logged in, I hope you have your current password, if not then get a local administrator to help you change your current. If you CAN log in, the process is simple, enter the following command at the prompt:


      Then you will be asked for a new password. Enter that, hit return, then it will ask you again for the password (usually it will say re-enter)… enter the same exact password that you just did, and that will change your password. NOTE that some systems require you to use a combination of characters, numbers, upper case, and non alpha-numeric characters. I would stay away from the “#” sign. On some really old systems that is used for backspace. :)

  • Reginaldo Sep 21, 2013 @ 2:03

    Thank you very much!

  • Hashan Chamikara Oct 13, 2013 @ 6:41

    Hello dear,

    i need to add active user in single command line.
    when i add user like useradd username -pPWD. but i cant log into linux using new username and password. please help me..

    Thank You

  • Davie Nov 7, 2013 @ 9:52

    Whenever I enter the new password all I get is authentication token manipulation error password unchanged. What am I doing wrong?

  • parshwa Nov 24, 2013 @ 3:44

    1. Boot the system and when you see the following message “Press any key to enter the menu”, press any key. (You will see the list of available kernel versions.)

    2. Press e in order to edit commands before booting.

    3. Highlight the list item with vmlinuz in it by using the arrow keys and press e.

    4. Now type single or init 1 at the end of the line.

    5. Then press enter and b to boot the system with the new argument. (The system will boot into single user mode and you will see bash prompt)

    Now it’s time to change the password:
    6. Type passwd

    7. Reboot system

  • parshwa Nov 24, 2013 @ 3:46

    Forgot to Add:

    To Reset forgotten root password on CentOS/Red Hat

  • Vaishali Dec 20, 2013 @ 8:39

    This works for me..Thanks.

  • Nimisha Mar 21, 2014 @ 15:41


  • sajan Jun 26, 2014 @ 14:12

    How to create a password and change password of a user account in VPN.

  • Albin Troja Oct 11, 2014 @ 19:32

    help help
    i have password changed, and i have logged without problems, after login is this problem

    this is from root after login

    login as: root
    root@‘s password:
    Last login: Sun Oct 12 01:24:10 2014 from che…123456789ipad01.3.g……s….at
    Changing finger information for root.
    Name [Albin Troja]:
    Office [albabin@l….de]:
    Office Phone [0676123456789]:
    Home Phone [0316010101010]:

    and closed automatically, please help me.

  • sadegh Oct 15, 2014 @ 16:42

    Hi. hw can I write a linux over older linux??

  • mahdi Dec 12, 2014 @ 5:41

    i have problem with root mode when i log in and enter password the Linux say
    what should i do and how the password i found it and change it .??

  • Robert Apr 1, 2015 @ 23:41

    Cool tutorial, but how to set a superuser password?

  • Jake Apr 4, 2015 @ 3:17

    I have no password set, so what do I put in when it asks for what my password is now? And it won’t even let me type in the space provided!

    • centos7-adm Mar 12, 2016 @ 17:13

      @Jake, to set a password for a user when you forgot to do type:
      passwd heretheusername , then it will ask to set a password (confirm it by re-typing)

  • Kanakaraj Feb 25, 2016 @ 5:08

    how to set default password for user in Linux ??

  • ajay mewada Feb 29, 2016 @ 10:25

    i have to set password for terminal in linux when open terminal through graphically or by shortcut key please give me suggession for this and do this by command

  • centos7-adm Mar 12, 2016 @ 17:24

    A nice simple article Vivek, but the problem as it seems are the ppl who can’t read :) Maybe you should ask if you need to chew also for them when they want to eat, joking.

  • karkadan Apr 5, 2016 @ 12:53

    i forgot the password of my Linux vmuser. what can i do ?
    thank you :)

  • Richmond Nov 23, 2016 @ 16:23

    wonderful page. It helped me beautifully.

  • Matt Dec 29, 2016 @ 16:13

    i did try this passwd command and it said token error. PLZ help me . i just set up my linux comp. too. and i dont want my password to be set to what they gave me

  • Mohan Oct 6, 2017 @ 8:07


    I have just added one user using command useradd. But when i try to set the password its asking for current password.Please help. Thanks

  • chrismint Oct 3, 2020 @ 10:28

    Thanks for the tutorial, really helped me a lot !

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