So, your trying to automate some tasks and leveraging PUTTY (PLink) but cant bet past the “host key not cached” message your presented with the very first time you login.

The Error message:
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 ##:##:##:##:##:##:##:##:##:##:##:##:##:##:##:## 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)

You can quickly get around this without having to login twice by using the following line to connect to your host the first time:
echo y | plink fully.qualified.domain.name
(replace “fully.qualified.domain.name” with the FQDN of your target or its IP -or- your variable)

What it does
This command connects to the host with plink, simulates a typed “Y” and then completes.  It probably shows up your devices logs as a failed authentication attempt.
If this concerns you, you could add “-l YourUsernameHere-pw YourPasswordHere exit” to the end of the command.  This will connect you to the box, pass the Y keystroke, authenticate, and exit.  You can replace the username/passwords with a variable as well.
So the command could look like : “echo y | plink fully.qualified.domain.name -l YourUsernameHere-pw YourPasswordHere exit”

 

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.