Search code examples
windowsbatch-filesshopenssh

BATCH file to connect to Linux via SSH. How?


First a screenshot that shows OpenSSH installed on Windows 10...

ssh

Above, I use the command ssh -V in the command prompt to make sure OpenSSH is installed.

Now.. It appears that throwing the following one liner into a .bat file to login to a linux server via ssh doesn't do anything.

ssh -p 22 root@10.10.1.100

When I type the same one liner into a windows 10 command prompt since Windows 10 now has OpenSSH built in, it logs me in just fine.

What I am missing?


Solution

  • Firstly, do not name your batch file ssh.bat or ssh.cmd and it will probably be best if you use the full path to the executable:

    @echo off
    "C:\Windows\System32\OpenSSH\ssh.exe" -p 22 root@10.10.1.100
    pause
    

    but it is probably better to use the %windir% environment variable:

    @echo off
    "%windir%\System32\OpenSSH\ssh.exe" -p 22 root@10.10.1.100
    pause