简体   繁体   English

在 scp 命令时传递 yes 参数

[英]passing yes argument while scp command

I am facing an issue when I run simply these commands.当我只运行这些命令时,我遇到了一个问题。

The remote server want to pass yes to 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.它仍在询问。

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.不过,适用于您不关心中间人的一次性拍摄。

For me, this works:对我来说,这有效:

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

Regards.问候。 =) =)

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

This will add the SSH_HOST to your known hosts and scp will not complain.这会将 SSH_HOST 添加到您的已知主机并且scp不会抱怨。 Substitute ${SSH_HOST} for the IP address you are trying to connect to.将 ${SSH_HOST} 替换为您尝试连接的 IP 地址。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM