Harry shah
Harry shah

Reputation: 397

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.

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

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

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.

Upvotes: 26

Views: 42460

Answers (3)

user1847
user1847

Reputation: 3799

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

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

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

Upvotes: 11

Chuss
Chuss

Reputation: 142

For me, this works:

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

Regards. =)

Upvotes: 9

economy
economy

Reputation: 4251

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.

Upvotes: 34

Related Questions