1

Good day all,

Please can you assist, I am trying to create a for loop to login to routers, load a script and logout all of this via SSH. The problem I am getting is I have 1500 routers I have to login to and I am getting a prompt to allow the fingerprint of the router and allow it.

Is there any way to bypass this Strict Host Key Checking and automatic accept it log in, load the scrip and log out.

I am using the plink.exe client. My code is below

plink.exe -ssh -batch ****@x.x.x.x -pw *** < "%~dp0cmd.txt"
  • is the prompt a Y/N prompt? Can you show example of this? – Gerhard Apr 19 '21 at 07:10
  • 1
    See [How to pass echo y to plink.exe for first connection](https://stackoverflow.com/q/38552236/850848) or [Using echo y as an automated response to a pcp hostkey prompt](https://stackoverflow.com/q/39924091/850848). – Martin Prikryl Apr 19 '21 at 07:39
  • The server's host key is not cached in the registry. You have no guarantee that the server is the computer you think it is. The server's rsa2 key fingerprint is: ssh-rsa 2048 0b:cb:e6:ef:fa:63:ee:ac:5d:6b:a5:28:86:15:9d:0c If you trust this host, enter "y" to add the key to PuTTY's cache and carry on connecting. If you want to carry on connecting just once, without adding the key to the cache, enter "n". If you do not trust this host, press Return to abandon the connection. Store key in cache? (y/n) Using username – Stefan Mostert Apr 19 '21 at 07:45
  • I would like to add that this does not work `echo y | plink.exe -ssh -batch ****@x.x.x.x -pw *** < "%~dp0cmd.txt` – Stefan Mostert Apr 19 '21 at 07:49
  • @Gerhard it is a Y/N - you can find the example in my first reply – Stefan Mostert Apr 19 '21 at 07:54
  • additionally, if it is more than one `Y/N` prompt, create a text file called `answer.txt` and enter `Y` in it twice, in list form. then try `(plink.exe -ssh -batch ****@x.x.x.x -pw *** < "%~dp0cmd.txt") – Gerhard Apr 19 '21 at 08:02
  • You cannot combine `|` and `<`. Either one or the other. – Martin Prikryl Apr 19 '21 at 08:02
  • @Gerhard I have tried your method, and it worked to bypass the Fingerprint and accept it automatically. The problem now is the cmd.txt which has the config that needs to be loaded. The good news is I can see that the connection successfully logs in on the router Logs. – Stefan Mostert Apr 19 '21 at 09:04
  • Well I think plink is not able to do what I want to do. Because it is not doing the command and it takes to long to log in. Think Linux is the best way out – Stefan Mostert Apr 19 '21 at 09:16
  • So did you try adding the `Y` to your `cmd.txt`?!? (not that I endorse this at all) – Martin Prikryl Apr 19 '21 at 09:17
  • @StefanMostert, ok, so that means it accepts the input, so try adding `Y` to the top line of the `cmd.txt` file and run the original `plink.exe -ssh -batch ****@x.x.x.x -pw *** < "%~dp0cmd.txt"` – Gerhard Apr 19 '21 at 09:27

0 Answers0