1

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.

Example:

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

# grep root /etc/shadow
root:-bashJ8av/8N:15709:0:99999:7:::
kernelpanic
  • 1,246
  • 1
  • 10
  • 30

1 Answers1

4

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

Like this

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

or

# usermod -p \$1\$0J8av/8N\$LIKB2G56XJn2IXp0XzERo1 root
coredump
  • 12,573
  • 2
  • 34
  • 53