Answer "yes" to ssh-copy-id first time run by script?

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

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 [email protected]

As an alternative, you could do the following:

echo "yes \n" | ssh-copy-id -i .ssh/id_dsa.pub [email protected]

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.