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 wxyzHowever 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_nameEverything 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?
76 Answers
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 %1and executed command from my windows cmd as below
2test_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.
1The below command is working for me as-is from inside of a bat file.
"D:\userdata\panshriv\Desktop\putty.exe" "pankaj@10.91.124.171" -pw "mypassword"
- My putty.exe is in my desktop
- My username is "pankaj"
- My password is "mypassword"
I use this code to input an IP address from the user. Fill in username and password with double quote "":
@echo off set /p START "C:\Program Files\putty.exe" -ssh %id% -l username -pw "password" @echo
there are two ways to do this::
- put your password in "" and run in command prompt as
start C:\software\putty.exe -ssh server_name -l user -pw "MyPassword$1"
OR
- Create a file Connection123.bat with below command
start C:\software\putty.exe -ssh server_name -l user -pw %1
save the file and run the batch file as
start c:\Connection123.bat MyPassword$1