解决SSH第一次登录需要交互确认的问题


i've been trying to issue commands using plink to retrieve information from my external server. note that these plink commands are ran from a binary that expects no input from the user. is there a flag that will allow me to override this error message and continue with program output?

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)

thank you!

share improve this question
 
 
The real issue is that either git doesn't properly give away input to plink or vice versa plink doesn't properly take it. If you launch git clone in, e.g. "git bash", the input (Y/n) goes then into bash prompt, and bash usually responds with bash: y: command not found. –  andrybak  Nov 18 '15 at 15:47

2 Answers

up vote 11 down vote accepted

Try prepending your script with:

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

This will pipe the y character through stdin to plink when you get the Store key in cache? (y/n)prompt, allowing all further plink commands to pass through without the need of user input. The exit command will close the SSH session after it has been established, allowing the following plink commands to run.

Here's an example script which writes the external server's Unix time to a local file:

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

Pipelining Referencehttp://tldp.org/HOWTO/Bash-Prog-Intro-HOWTO-4.html

share improve this answer
 
 
wow that worked, thanks –  Tad Oh  Aug 23 '12 at 18:54

maybe, it will help:

plink -auto_store_sshkey -batch 192.211.158.256 -l user -pw password command
share improve this answer
 
 
-auto_store_sshkey is an "unknown option" for plink version 0.63 –  Nathan  Aug 20 '14 at 18:49
 
Unknown to 0.66 too –  Joril  Dec 18 '15 at 14:39

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值