Linux Set or Change User Password

by on September 21, 2006 · 43 comments· LAST UPDATED May 27, 2010

in

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.



If you would like to be kept up to date with our posts, you can follow us on Twitter, Facebook, Google+, or even by subscribing to our RSS Feed.


{ 43 comments… read them below or add one }

1 bambi April 24, 2007 at 7:22 am

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.

Reply

2 ivonne saucedo January 29, 2012 at 4:38 pm

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

Reply

3 Rick February 12, 2008 at 3:02 am

thanks this help alot

Reply

4 Aloka February 3, 2009 at 7:52 am

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.

Reply

5 ajit October 12, 2010 at 8:05 am

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

Reply

6 niono November 30, 2010 at 3:31 am

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

Reply

7 mansoorali February 24, 2011 at 9:50 am

hi
useradd u1
passwd u1

Reply

8 Andy February 17, 2009 at 3:19 am

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.

Reply

9 Chloe May 7, 2009 at 8:19 pm

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

Reply

10 Atta May 28, 2009 at 9:54 pm

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

Reply

11 Varun September 10, 2009 at 8:02 am

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

Reply

12 AeSix September 11, 2009 at 4:50 am

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.

Reply

13 UnixOS September 12, 2009 at 11:24 am

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

Reply

14 abbakus October 8, 2009 at 5:54 pm

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.

Reply

15 -Pablo- June 28, 2010 at 2:39 pm

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.

Reply

16 deepak mishra November 16, 2009 at 8:39 am

i ,m forget passwd then i can do

Reply

17 Talib November 18, 2009 at 10:09 am

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

Reply

18 lokesh December 5, 2009 at 5:20 am

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

Reply

19 Charlie Seah Kam Fei January 28, 2010 at 9:26 am

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

Reply

20 Charlie January 28, 2010 at 9:27 am

Any files in Linux support that? Thanks in advance

Reply

21 G.Shoba June 12, 2010 at 4:49 pm

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…

Reply

22 Aamir Ali July 1, 2010 at 3:42 pm

Helpful. Thanks.

Reply

23 aisha August 10, 2010 at 11:31 pm

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

Reply

24 -Pablo- August 11, 2010 at 12:30 am

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.

Reply

25 aisha August 11, 2010 at 4:54 pm

thank you that helped

Reply

26 steve August 31, 2010 at 11:12 am

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

Reply

27 NinjaSysadmin June 22, 2011 at 2:06 pm

#!/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.

Reply

28 dr nandinee October 31, 2010 at 7:59 pm

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

Reply

29 karthi January 31, 2011 at 7:55 am

hello nandini which flavour r u using…..

Reply

30 DR. HYDE July 1, 2011 at 8:37 am

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?

Reply

31 madhusudhana T June 13, 2011 at 9:01 am

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

Reply

32 Balaviswanathan July 5, 2011 at 11:49 am

Hi,

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

Thanks in advance

Reply

33 satti July 8, 2011 at 1:48 pm

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.

Reply

34 sravn August 4, 2011 at 6:30 am

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

Reply

35 Ramesh Adapwar December 23, 2011 at 10:11 am

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

Reply

36 steven March 29, 2012 at 5:19 pm

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

Reply

37 sachin May 30, 2012 at 8:10 am

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

Reply

38 Paresh August 6, 2012 at 3:15 pm

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

Reply

39 Gelo August 7, 2012 at 9:56 am

do any version of linux support this?

Reply

40 Gelo August 7, 2012 at 9:59 am

is it the same on all version of linux?

Reply

41 Boyd October 22, 2012 at 2:34 pm

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

Reply

42 vaibhav kanchan December 5, 2012 at 7:11 am

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?

Reply

43 ranga santhosh April 15, 2013 at 4:08 am

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

Reply

Leave a Comment

You can use these HTML tags and attributes for your code and commands: <strong> <em> <ol> <li> <u> <ul> <kbd> <blockquote> <pre> <a href="" title="">

Tagged as: , , , , , , , , , , , , , , , , , ,

Previous Faq:

Next Faq: