21
[root@P-dude dude]# useradd -p $6$Ic2PVlwi$2nf.IRWTMy0FHrPzaCjkahfu9IIxnzxPZL7yg8SsvOdbjEpoI0G8uy7AqduYKQOn2R/rnnaalRmfPMy.a0 bwong20

[root@P-dude dude]# cat /etc/shadow | grep pswayze
pswayze:nf.IRWTMy0FHrPeaCjkahfufIIxnzxPZL7yg8SsvOdbjEpoI0G8uy7AqduYKQOn2R/rnnaalRmfPMy.a0:16924:0:99999:7:::

I'm not sure why the system removes the first fourteen characters from my encrypted password. The password in my /etc/shadow file is shorter than what I've provided as an argument to useradd -p

PolkaRon
  • 367
  • 5
  • 17
  • Of course, it should go without saying that you need to use a different password now you've exposed this hash. ;) – Wildcard May 04 '16 at 02:21

1 Answers1

67

Because $ is a special character to the shell you should put the password in between single quotes:

useradd -p '$6$Ic2PVlwi$2nf.IRWTMy0FHrPza6mh5wjomwbYtIIxnzxPZL7yg8SsvOdbjEpoI0G8uy7AqduYKQOn2R/rnnaalRmfPMy.a0' bwong20

without these the shell will try to expand $6, $Ic2PVlwi and $2 to their respective variable values, and as the variables are not set, result in empty strings for each of them. Concatenated to the rest of the encrypted password string.

Anthon
  • 78,313
  • 42
  • 165
  • 222