Non-interactive scp
Asked Answered
R

2

10

I'm creating a bash script to create new EC2 instances and then upload a file once the instance is created. I'm using scp to upload the file, however, since this is the first time I'm connecting to the instance the script is prompted with "Are you sure you want to continue connecting (yes/no)?" since the authenticity of the host is not known. The script needs to run non-interactively.

Is it possible to avoid the prompt (there doesn't seem to be an obvious command line option). If not is there an alternative method or command I can use to upload the file?

Rollet answered 7/9, 2009 at 14:52 Comment(1)
I'm in the same situation. I have a large amount of boxes SCP'ing around and have the same problem. I investigated many hours into this issue but haven't found an appropriate solution. Looking forward for answers!Confucius
W
11

You can set the option StrictHostKeyChecking to no in ~/.ssh/config. See ssh_config(5)

This can also be done from the command line: scp -i id -o stricthostkeychecking=no source.txt user@host:/path/

Where id is a private key where the corresponding public key resides in the authorized_keys file on the server

Washerman answered 7/9, 2009 at 15:9 Comment(2)
Ah, that is a cleaner solution than mine :-). Although it probably is lots safer to create a separate config file used only for the script and specify that using the -F <configfile> switch.Graiggrail
This can also be done from the command line "scp -o StrictHostKeyChecking=no ..."Rollet
G
0

Although maybe not the definitive and safest solution, you could try writing an expect script.

Graiggrail answered 7/9, 2009 at 15:11 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.