Linux Set or Change User Password

Posted on in Categories , last updated May 27, 2010

How do I set or change Linux system password for any user account?

Both Linux and UNIX use the passwd command to change user password. The passwd is used to update a user’s authentication token (password) stored in shadow file.

The passwd changes 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’s login shell, or password expiry date and interval.

Task: Set or Change User Password

Type passwd command as follows to change your own password:
$ passwd
Output:

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 6 to 8 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

Task: Change Password For Other User Account

You must login as root user, type the following command to change password for user vivek:
# passwd vivek
Output:

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

Where,

  • vivek – is username or account name.

Task: 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.

70 comment

  1. 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.

  2. hi!
    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.

      1. 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

  3. 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.

  4. 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

    1. 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

  5. Hi

    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

  6. Hi,
    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.

    Anyone?

    Thanks.

    1. 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.

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

  7. 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!~

  8. 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…

    1. 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.

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

    #!/bin/sh
    for i in $(seq 1 70)
    do
    useradd -d/home/te$i -m te$i
    done

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

    1. #!/bin/sh
      for i in $(seq 1 70)
      do
      useradd -d/home/te$i -m te$i
      echo $i:xyz | chpasswd
      chage -d 0 $i
      done

      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.

      1. 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?

  10. Hi,

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

    Thanks in advance

  11. hi!
    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.

  12. 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?

    1. 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:

      passwd

      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. :)

  13. 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

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

  15. 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

  16. 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
    [email protected]‘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 [[email protected]….de]:
    Office Phone [0676123456789]:
    Home Phone [0316010101010]:

    and closed automatically, please help me.

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

  18. 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!

    1. @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)

  19. 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

  20. 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.

  21. 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

Leave a Comment