I have two machines which have the same set of users on each. I have a script on one machine that I want to change the password on both machines.
So, I generate a random password, then hash it, and pass it to the usermod command, like this:
usermod -p PASSWORD_HASH USER ssh REMOTE_USER@REMOTE_HOST sudo usermod -p PASSWORD_HASH USER
The REMOTE_USER has privileges to execute that command using sudo without requiring a password.
The outcome of this is that the password is successfully changed on the local machine, which I can verify immediately by attempting:
I also checked the /etc/shadow file, and it appears that the hash is indeed stored correctly.
However, if I jump over to the other machine and attempt to login as USER there, I can't get in. I get an authentication error. If I log in on the remote machine with superuser privileges and check the /etc/shadow file, the password hash is totally garbled and doesn't make any sense.
However, if, while on that remote machine, I execute the exact same command without going over ssh, using
sudo usermod -p PASSWORD_HASH USER
Then everything works just fine.
Is there some detail here I'm missing that is causing the usermod command NOT to work over ssh for some reason?