I'm trying to implement an automated root password change for our Linux boxes. I'm generating a hash in the script since users will be able to see the contents of the script.

I found that you can pass a hash with the usermod utility. However, I'm running into a variable substitution issue as seen below.


# usermod -p $1$0J8av/8N$LIKB2G56XJn2IXp0XzERo1 root

# grep root /etc/shadow

1 Answer 1


Surround the password on the usermod command with single quotes '' or escape the $ with '\$'

Like this

# usermod -p '$1$0J8av/8N$LIKB2G56XJn2IXp0XzERo1' root


# usermod -p \$1\$0J8av/8N\$LIKB2G56XJn2IXp0XzERo1 root
  • Thanks, the single quotes worked. I was trying double quotes. Jan 4, 2013 at 15:06
  • Double quotes, as you noticed, still allow for variable interpolation. Single quotes on the other hand, don't.
    – coredump
    Jan 4, 2013 at 15:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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