Run remote command with putty
When I do putty -ssh user@host -pw password echo "hi"
I get a network error
But if I do putty -ssh user@host -pw password
An SSH session is successfully opened in a putty terminal. But I just want to run a single command. How do I do this in Putty?
You might want to use plink
(which is shipped with putty) instead of putty for this.
Quote from the documentation:
Plink is a command-line connection tool similar to UNIX `ssh'. It is mostly used for automated operations, such as making CVS access a repository on a remote server.
For your example:
plink -ssh user@host -pw password echo "hi"
Per the putty manual, there is only -m
which can be used to give it a file containing one or more commands to be executed in sequence.
As @GeraldSchneider suggests, PLINK is more suitable, but if you really wanted to use PuTTY this is how you could do it:
First, you need to set a few things up as follows:
- Connect to the remote box via PuTTY, as in your example.
- While on the remote box, create a script to echo "hi". Name it
hello.sh
. - Right-click the PuTTY window caption and select 'Change Settings...".
- Type the name
my-saved-session
and click Save then Cancel. - Exit the session. Open the PuTTY Configuration panel again.
- Select your saved
my-saved-session
session and click Load. - On the left of the 'Category' tree view, click 'SSH'.
- In the 'Remote command' box type
/hello.sh -o
. - Click back on 'Session' and click Save.
Now you're good to run the command:
putty -ssh user@host -pw password -load my-saved-session