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:
- Run
ssh-keyscan
against the target server to get the public key - Append that to the known_hosts file
- 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.