Windows Batch File – How to SSH to a Remote Server Using PuTTY

batch fileputtysshwindows

On Windows I use PuTTY to log in to a remote server via SSH. I want to use a batch script to SSH to the remote server using PuTTY. The server is running a Linux-based OS.

I used the below command to do this:

start C:\Windows\System32\putty.exe -ssh server_name -l pankmish -pw wxyz

However I got the following error:

unable to connect to remote host

If I use this command instead:

start C:\Windows\System32\putty.exe -ssh server_name -l user_name

Everything works well and I get a PuTTY window with username "user_name" in it. If I provide the correct password I am able to connect to the server. However via a batch script I am not able to provide the password when prompted.

How can I solve this?

Best Answer

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

Related Question