Saturday 23 March 2019

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


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?



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



No comments:

Post a Comment

How can I VLOOKUP in multiple Excel documents?

I am trying to VLOOKUP reference data with around 400 seperate Excel files. Is it possible to do this in a quick way rather than doing it m...