Putty won't cache the keys to access a server when run script in hudson

Charlotte Xu picture Charlotte Xu · Nov 28, 2012 · Viewed 72.5k times · Source

I had a simple automation process to write which needed to copy a few files from linux server to windows via SSH. This can be accomplished using putty.

SSH, as part of the protocol, verifies the host’s identity and if not known to be correct, will prompt you to accept the host’s identity. When I manually connect the linux server with putty , it won’t prompt any information to accept the host’s identity. But once I put this automation process into Hudson as schedule job. The exact message was:

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 1024 cc:78:13:a3:68:a6:59:7e:b8:23:2d:13:3e:66:9b:b9 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) Connection abandoned.

Usually you would hit “Y” here, assuming the host key is correct, in order to store it in future connection. The storage of this goes into the Registry under HKEY_CURRENT_USER\Software\SimonTatham\Putty\SshHostKeys

But unfortunately , the automation process running in Hudson cannot do interaction by hit “Y” to store host key in putty cache. And also I cannot reproduce the issue by simply run the automation process under dos command.

Does anyone know how to resolve the problem?

Answer

Jay picture Jay · Nov 29, 2012
echo y | pscp -i /path/to/key/file user@remote:/tmp/file  .
echo y | plink -i /path/to/key/file scripts.sh

it will store host key fingureprint to following location at the first time, and will ignore "y" next time

HKEY_CURRENT_USER\Software\SimonTatham\PuTTY\SshHostKeys