1

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:

su USER

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?

1 Answer 1

1

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.

1
  • Perfect, thank you. I quoted and escaped the entire command passed to ssh and everything works now. Aug 17, 2016 at 21:44

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .