在scp命令时传递yes参数

当我简单地运行这些命令时,我正面临一个问题。

由于首次与scpbuild立连接,因此远程服务器要通过yes来添加RSA文件中的密钥。

命令如下

 #!/bin/bash scp -P58222 root@IP:/root/K /N /usr/bin/expect -c 'expect "\n" { expect "Are you sure you want to continue connecting (yes/no)?" }' send "yes\r" expect "$ " send "exit\r" 

其实我一定要在我的剧本中通过肯定的要求

主机的IP地址(IP地址)的真实性不能build立。

 RSA key fingerprint is xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx. Are you sure you want to continue connecting (yes/no)? 

你确定要继续连接(是/否)吗?

我怎样才能摆脱这个问题?

 scp -o StrictHostKeyChecking=no 

它仍然在问。

 scp -o StrictHostKeyChecking=no root@IP:/root/K 

显然,这不是一个非常安全的解决方案。 尽管如此,在你不关心中间人的情况下,你可以单打一杆。

对我来说,这个工作:

  yes | scp -r /opt/MyFiles root@<MyNewserverIP>:/opt/MyFiles 

问候。 =)