25

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.

3
  • 2
    You can just pass arguments to ssh/scp to tell it not to ask the question; no need to use expect to script the answer. Mar 31, 2015 at 16:56
  • 1
    That said -- which specific question are you telling it to auto-answer yes to? If it's an unknown-host-key question, for instance, that would help. Mar 31, 2015 at 16:57
  • specifically, scp -q enables quiet mode, which doesn't need to ask for confirmation.
    – Hans Z
    Mar 31, 2015 at 17:01

3 Answers 3

34
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.

5
  • Actually, when connection established it show connection can't established because remote host info not added when we type yes it display host machine info added successfully.
    – Harry shah
    Mar 31, 2015 at 17:05
  • I'd suggest looking at man scp under the -o option for a full list of ssh/scp options. Depending on your setup, you may need another option flag set.
    – economy
    Mar 31, 2015 at 17:09
  • I am checking it is helpful but now testing ..!!
    – Harry shah
    Mar 31, 2015 at 17:25
  • 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)? it is still asking that
    – Harry shah
    Mar 31, 2015 at 17:41
  • Try redirecting the known hosts file to /dev/null: scp -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no...
    – economy
    Mar 31, 2015 at 19:56
10

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.

2
  • 1
    This should be accepted answer because we aren't disabling any security features... Oct 8, 2020 at 14:11
  • It solved my problem. Oct 23 at 12:25
9

For me, this works:

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

Regards. =)

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.