Auto-storing server host key in cache with plink
Solution 1:
Try prepending your script with:
echo y | plink -ssh root@REMOTE_IP_HERE "exit"
This will pipe the y
character through stdin
to plink
when you get the Store key in cache? (y/n) prompt, allowing all further plink
commands to pass through without the need of user input. The exit
command will close the SSH session after it has been established, allowing the following plink
commands to run.
Here's an example script which writes the external server's Unix time to a local file:
echo y | plink -ssh root@REMOTE_IP_HERE "exit"
plink -ssh root@REMOTE_IP_HERE "date -t" > remote_time.tmp
Pipelining Reference: http://tldp.org/HOWTO/Bash-Prog-Intro-HOWTO-4.html
Solution 2:
PuTTY
and plink.exe
share the same cache of 'acceptable server keys' on the host they are installed on.
So if your scenario is interactive (and hence your frustration not being heard when you press 'y' or 'n'), a workaround is to attempt a connection with PuTTY first.
When doing this:
- You'll open
PuTTY
and pretend to start an interactive SSH session to the server - You'll get a Windows dialog box showing the key asking if you want to trust it
- You'll check the presented key, to ward of MITM's, then press
OK
- Henceforth,
plink.exe
won't bother to ask if you trust the server or not - it already knows you do