Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

The first time ssh-copy-id it will ask

# ssh-copy-id -i .ssh/id_dsa.pub backup@example.com
The authenticity of host 'example.com (xxx.xxx.xxx.xxx)' can't be established.
RSA key fingerprint is 39:fb:5e:70:30:33:2b:18:17:e9:4f:2f:91:b5:d2:21.
Are you sure you want to continue connecting (yes/no)? 

Is it possible to script this, so the script just will answer yes?

share|improve this question
    
serverfault.com/a/321181/59925 –  quanta Aug 30 '12 at 16:39
add comment

2 Answers

up vote 3 down vote accepted

If your ssh-copy-id doesn't support the StrictHostKeyChecking option, you can write a script that does:

  1. Run ssh-keyscan against the target server to get the public key
  2. Append that to the known_hosts file
  3. Run ssh-copy-id
share|improve this answer
add comment

SSH has an option to automatically add any host keys to the trusted hosts file:

ssh-copy-id -i .ssh/id_dsa.pub -o StrictHostKeyChecking=no backup@example.com

As an alternative, you could do the following:

echo "yes \n" | ssh-copy-id -i .ssh/id_dsa.pub backup@example.com

Edit: since it appears these solutions don't work with ssh-copy-id, you could always create a ~/.ssh/config file with the following option in it:

StrictHostKeyChecking no

This should work with all SSH connections, regardless if they are invoked through a script or not.

share|improve this answer
    
Sadly doesn't work, and ssh-copy-id doesn't have -o –  Sandra Aug 30 '12 at 13:17
    
Weird, it does report that switch when issuing ssh-copy-id -? –  brain99 Aug 30 '12 at 13:24
1  
@sandra ssh-copy-id is a script. You can modify it to add -o StrictHostKeyChecking=no or disable that parameter in the ssh_config file. –  ewwhite Aug 30 '12 at 13:24
    
Also, you don't need to specify the key location... ssh-copy-id servername works fine. –  ewwhite Aug 30 '12 at 13:26
    
sudo sed -i.bak 's/ssh \$/ssh -o StrictHostKeyChecking=no \$/' $(which ssh-copy-id). –  quanta Aug 30 '12 at 16:47
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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