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

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

来源  https://serverfault.com/questions/420526/auto-storing-server-host-key-in-cache-with-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)

尝试在脚本前添加:

echo y | plink -ssh root@REMOTE_IP_HERE "exit"

这将管道y通过角色stdinplink当你在高速缓存中存储的关键?(y / n)提示,允许所有其他plink命令通过而无需用户输入。exit建立SSH会话后,该命令将关闭SSH会话,从而允许plink运行以下命令。

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

echo y | plink -ssh root@REMOTE_IP_HERE "exit"
plink -ssh root@REMOTE_IP_HERE "date -t" > remote_time.tmp

管道参考:http : //tldp.org/HOWTO/Bash-Prog-Intro-HOWTO-4.html

========= End

原文地址:https://www.cnblogs.com/lsgxeva/p/14222739.html