Create a batch file or shortcut to PuTTY (ssh) that opens a session and runs a command
Use the commandline PuTTY version plink.exe
to initate a SSH connection to a host of choice. Use the -ssh
switch to connect with SSH. With the -m
switch you can include a command file:
plink.exe -ssh host1 -m C:\path\to\commands.txt
You can download plink.exe
from here.
Last step would be to create a shortcut including plink.exe
with the desired parameters.
Check out the Plink documentation for other various parameters: Plink.exe documentation
To automate a command execution, use Plink (from PuTTY package), not PuTTY itself.
Plink accepts a command on its command line:
plink.exe user@host command
If you want to keep using PuTTY, you can use -m
switch to specify a command file (Plink supports the -m
switch too).
You can use putty configurations to achieve this.
Load putty and configure your session.
Enter the remote command that you'd like to run here:
Then, before clicking "Open", go back to the "Session" tab (at the top), and save your configuration.
Now, create a shortcut to putty.exe
, adding the -load
flag, for example:
%PATH_TO_PUTTY%\putty.exe -load my_config
Now, you can just click on the shortcut and it will load your session, executing your command.
If you're using Windows 10, you might be interested to know that Microsoft reportedly has a beta of OpenSSH (client and server):
[…] go to “Manage Optional Features” then + “Add a feature”. You can then scroll down the list and find the OpenSSH Client (Beta) and OpenSSH Server (Beta) features in Windows. The idea of running another remote service on Windows can be daunting so we do not blame you if you do not want to install the server.
Once installed, you can simply fire up your command line and use the OpenSSH client by typing ssh followed by the command such as
ssh ubuntu@someIP
.Here is the current (as of November 28, 2017)
ssh
command usage guide we are getting with the Windows OpenSSH Client:C:\WINDOWS\system32>ssh usage: ssh [-46AaCfGgKkMNnqsTtVvXxYy] [-b bind_address] [-c cipher_spec] [-D [bind_address:]port] [-E log_file] [-e escape_char] [-F configfile] [-I pkcs11] [-i identity_file] [-J [user@]host[:port]] [-L address] [-l login_name] [-m mac_spec] [-O ctl_cmd] [-o option] [-p port] [-Q query_option] [-R address] [-S ctl_path] [-W host:port] [-w local_tun[:remote_tun]] [user@]hostname [command] C:\WINDOWS\system32>
If this works, you should be able to use ssh
like you would on a *Nix:
C:\WINDOWS\system32>ssh user@host "ls -l ~"