将SSH主机密钥添加到其他用户的PuTTYcaching

我已经写了一个PS1脚本,它可以将一个文件夹拉到一个文件中,然后使用PuTTY的SCP将其存储在我的备份服务器上。 我已经testing过,它完美的工作。

然后,我login到SQL Server代理,并在备份工作完成后,为备份作业添加一个额外的步骤,以执行该脚本。 它被正确调用,.7z文件被创build,并且pscp.exe被调用…并暂停。 我去SQL Server代理的作业活动监视器,并find这个:

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 b5:f8:d2:5f:be:90:b6:be:15:d3:26:d5:c6:42:59:05 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) 

现在这是一个非互动的会议,所以我没有机会在那里按“y”。 最重要的是,我不知道这个工作在哪个用户上运行,即使我知道,我也不知道这个caching在哪里。 现在怎么办?

你可以做类似的事情

 echo n | pscp file.7z [email protected]:/path 

这允许复制继续而不将密钥指纹存储在registry中。 或者你可以

 echo y | pscp file.7z [email protected]:/path 

这将接受该问题并将密钥指纹添加到用户HKEY_CURRENT_USER\Software\SimonTatham\PuTTY\SshHostKeys

将选项-batch添加到您的脚本文件。