bash 在 scp 命令时传递 yes 参数

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/29374144/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-18 12:41:52  来源:igfitidea点击:

passing yes argument while scp command

linuxbashscriptingscp

提问by Harry shah

I am facing an issue when I run simply these commands.

当我只运行这些命令时,我遇到了一个问题。

The remote server want to pass yesto add the key in RSA file because first time connection established with scp.

远程服务器希望通过yes将密钥添加到 RSA 文件中,因为第一次使用scp.

commands are given below

命令如下

#!/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"

Actually I have to pass yes in my script while asking

实际上我必须在我的脚本中通过 yes 在询问时

The authenticity of host 'ip address (ip address)' can't be established.

主机'ip地址(ip地址)'的真实性无法建立。

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)? 

Are you sure you want to continue connecting (yes/no)?

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

how can I get rid of this problem?

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

with

scp -o  StrictHostKeyChecking=no

it is still asking.

它仍在询问。

回答by economy

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

Obviously, this isn't a very secure solution. Works for one-shots where you're not concerned about man in the middle, though.

显然,这不是一个非常安全的解决方案。不过,适用于您不关心中间人的一次性拍摄。

回答by Chuss

For me, this works:

对我来说,这有效:

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

Regards. =)

问候。=)

回答by Colton Hicks

Probably the best way to do this would be to use the following command before your scp command:

可能最好的方法是在 scp 命令之前使用以下命令:

ssh-keyscan -H ${SSH_HOST} >> ~/.ssh/known_hosts

ssh-keyscan -H ${SSH_HOST} >> ~/.ssh/known_hosts

This will add the SSH_HOST to your known hosts and scpwill not complain. Substitute ${SSH_HOST} for the IP address you are trying to connect to.

这会将 SSH_HOST 添加到您的已知主机并且scp不会抱怨。将 ${SSH_HOST} 替换为您尝试连接的 IP 地址。