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


21

我一直在尝试使用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)

谢谢!


真正的问题是git不能正确地将输入提供给plink,反之亦然plink不能正确地使用它。如果git clone以“ git bash”启动,则输入(Y / n)进入bash提示符,bash通常以响应bash: y: command not found
andrybak

您可以使用kitty项目中的 klink 。这是油灰的叉子。有关键:-auto-store-sshkey。
paxlo

Answers:


20

尝试在脚本前添加:

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


By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.