Execute a remote script on a remote computer via SSH

I have a bash script on Machine B which I want to run on Machine B. I am using Machine A right now. Is this possible?

So far I've only managed to do it if the script lives on Machine A using the following command:

ssh user@machineb 'bash -s' < /path/machinea/script.sh

I don't want to have to copy this remote script locally. Is there a way to run this remote script on a remote machine through my local machine via SSH?


From man ssh:

If command is specified, it is executed on the remote host instead of a login shell.

where command is the last argument of ssh

Therefore, the only thing you have to do is move the single quote:

ssh user@machineb 'bash -s < /path/machinea/script.sh'

Basically the command you provided above redirects the machine A script to ssh, which transmits the script through the network and runs it in machine B. Even less hassle to run scripts/commands locally on machine B.