使用 plink 在缓存中自动存储服务器主机密钥

Tad*_* Oh 27 ssh putty host plink

我一直在尝试使用 plink 发出命令以从我的外部服务器检索信息。请注意,这些 plink 命令是从不需要用户输入的二进制文件中运行的。是否有一个标志可以让我覆盖此错误消息并继续程序输出?

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)
Run Code Online (Sandbox Code Playgroud)

谢谢!

Dan*_* Li 26

尝试在你的脚本前加上:

echo y | plink -ssh root@REMOTE_IP_HERE "exit"
Run Code Online (Sandbox Code Playgroud)

当您在缓存中获取Store 键时,这会将y字符通过管道传递stdin给它吗?(y/n)提示,允许所有进一步的命令通过而无需用户输入。该命令将在建立后关闭 SSH 会话,从而允许运行以下命令。plinkplinkexitplink

这是将外部服务器的 Unix 时间写入本地文件的示例脚本:

echo y | plink -ssh root@REMOTE_IP_HERE "exit"
plink -ssh root@REMOTE_IP_HERE "date -t" > remote_time.tmp
Run Code Online (Sandbox Code Playgroud)

流水线参考http : //tldp.org/HOWTO/Bash-Prog-Intro-HOWTO-4.html


Clé*_*ezo 5

接受的答案是“可以接受”,但不安全。最好的方法是指定 plink 的主机密钥以防止任何中间人攻击。

plink -hostkey aa:bb:cc... root@REMOTE_IP_HERE [...]
Run Code Online (Sandbox Code Playgroud)