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:


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.

My question:

Is there some detail here I'm missing that is causing the usermod command NOT to work over ssh for some reason?


See this related answer. In short, SSH passes whatever follows it as a string, not as a list of arguments, so enclose it in quotes. And you may want to insert a && before that last sudo.

  • Perfect, thank you. I quoted and escaped the entire command passed to ssh and everything works now. – Jared Brandt Aug 17 '16 at 21:44

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.