将 SSH 主机密钥添加到另一个用户的 PuTTY 缓存

将 SSH 主机密钥添加到另一个用户的 PuTTY 缓存

我编写了一个 PS1 脚本,它可以对文件进行 7-zip 压缩,并使用 PuTTY 的 SCP 将其存储在我的备份服务器上。我已经测试过了,它运行良好。

然后我登录到我的 SQL Server 代理,并向我的备份作业添加一个额外的步骤,以便在备份作业完成后立即执行该脚本。它被正确调用,.7z 文件被创建,pscp.exe 被调用……然后停止。我转到 SQL Server 代理的作业活动监视器并发现以下内容:

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”。最重要的是,我不知道这个作业在哪个用户上运行,即使我知道,我也不知道这个缓存在哪里。现在怎么办?

答案1

在本地会话中添加 SSH 指纹后,您还可以转到注册表

HKEY_CURRENT_USER\Software\SimonTatham\PuTTY\SshHostKeys

并将密钥复制给其他用户,例如

HKEY_USERS\.DEFAULT\Software\SimonTatham\PuTTY\SshHostKeys

本地系统用户

HKEY_USERS\S-1-5-18\Software\SimonTatham\PuTTY\SshHostKeys

答案2

你可以做类似的事情

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

这允许复制继续,而无需将密钥指纹存储在注册表中。或者,您可以

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

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

答案3

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

相关内容