I was looking all over the internet for how to connect to my raspberry Pi 4 using a batch file. Most of the articles end up using Putty. Windows 10 has a built in ssh server which is what I wanted to use.
I found that there are a couple of methords to do this my first attempt was to create the batch file by creating a new text file and just renaming it with the extention .bat this worked when I had dos way back in the 80's I knew if I put cmd /k in the file this would just open a new cmd window. So I was nearly there!
What I had to figure out was where was the ssh server this is where I found it in my computer C:\Windows\System32\OpenSSH\ssh.exe with a little help from various sources I found that
cmd /k C:\Windows\System32\OpenSSH\ssh.exe -p 22 pi@192.168.1.1
This opened and connected to my pi which then asked for my password bam your in.
what the code above does is goes to the directory runs ssh and connects user. The bits I have in bold are the bits you will need to change. Use your username@change 192.168.1.1 to the address you normally connect to you pi with.
other have said rather than use c:\windows you can use %windir% so this is how it would look cmd /k "%windir%\System32\OpenSSH\ssh.exe" -p 22 pi@192.168.1.1
so to put it all together you can use either method it's up to you.
@ECHO OFF ECHO Batch file to connect to PI server with ssh. C:\Windows\System32\OpenSSH\ssh.exe -p 22 pi@192.168.1.1
Put the above code into you batch file and you are read to connect
Hope this has been of help.
------------- Admin - Guido
http://www.amodel4hire.co.uk - http://www.amodel4hire.co.uk
|