I effectively have a sticky keyboard (host machine to RDP to vCenter to virtual console), but need to update the password of a VM I am building.

Using the rescue environment CentOS media offers, I can chroot to the installed system and run passwd, but after typing the password once, I inevitably get an error that the password tokens do not match. (Sometimes typing "passwd" echoes back "passsswwdddd" or similar on the commandline.)

How can I update root's password without needing to enter it twice?

Because I don't know the password, I cannot ssh (which would eliminate the sticky keyboard issue) - hence using a rescue environment and chroot.

  • Updating the root password without knowing what it is (because of the sticky keyboard) doesn't seem very useful. – dhag Mar 17 '15 at 19:03
  • @dhag - if I can pass it on the commandline, however, I can fix any stickiness experienced using the remote access options I have available to my lab – warren Mar 17 '15 at 19:05
  • 3
    You can run usermod -p encryptedpassword . You can use something like openssl passwd ... to generate the encrypted password. – Mark Plotnick Mar 17 '15 at 19:15

You might be able to use some form of:

# echo "Th3P@ssw0rd" | passwd --stdin theUser

assuming your version of the passwd binary supports the --stdin option.


I use this trick in scripts if an interactive prompt has to be used:

yourpass='My supersecret password'
$(echo $yourpass; echo $yourpass) | passwd username

Basically assign the password to a variable and use that in the following command.


Try this one:

# echo 'root:PASSWORD' | chpasswd

Please replace PASSWORD with the one you want. It works well for me in Suse Linux.


Based on Mark Plotnick's comment,

vi passfile
usermod -p `openssl passwd stdin < passfile` root
rm -f passfile

This gives you the opportunity to edit the temporary file and confirm that you have set the password to what you really think it is. It also keeps the password out of any history, etc.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.