SSH to a remote server using PuTTY through Windows batch file?

I tried passing the password using command line and it worked fine for me.

start C:\Users\pankmish\Downloads\putty.exe -ssh server_name -l user -pw %1

and executed command from my windows cmd as below

test_file.bat password


Make sure that putty is installed and putty.exe is present in C:\Windows\System32

Open up notepad: Type in the following

start putty <username@ip/hostname> -pw <password>

Replace the above with your username, ip and password and save the file as .bat file. I think that should do it.


You may try the same trick of this answer:

@if (@CodeSection == @Batch) @then

@echo off

rem Use %SendKeys% to send keys to the keyboard buffer
set SendKeys=CScript //nologo //E:JScript "%~F0"

rem Start the putty window with the user name only
start C:\Windows\System32\putty.exe -ssh server_name -l user_name

rem Send the password to putty window
%SendKeys% "wxyz{ENTER}"

goto :EOF

@end

WScript.CreateObject("WScript.Shell").SendKeys(WScript.Arguments(0));

Please, post the result.


The below command is working for me as-is from inside of a bat file.

"D:\userdata\panshriv\Desktop\putty.exe" "[email protected]" -pw "mypassword"

  • My putty.exe is in my desktop
  • My username is "pankaj"
  • My password is "mypassword"