Run a single command on putty start

You need to write your command in a file first. Then you can use -m option of putty.exe:

putty.exe -ssh [email protected] -P 22 -pw password -m C:\fileWithCommand

It depends on the system's OS which you want to access via SSH whether it is possible to write even a batch of commands in this file.

Above method can execute whole scripts but closes the session when terminated. If you want to have the output, download plink.exe:

plink.exe -ssh [email protected] -P 22 -pw password echo test

This command prints test.

-P 22 is not necessary in the case your port is 22.


For those who are having issue that putty exits after execution when we use -m, we need to give "-t" option at the end so that the session remains interactive.

putty.exe -ssh example.com -m "c:\pathOfCommandFile\cmd.txt" -t

So on windows, basically we can create a shortcut and in its property put the whole statement as above. In cmd.txt put the command to execute. You may have to give absolute path of putty.exe (example: C:\Program Files\PuTTY\putty.exe)