Answer "yes" to ssh-copy-id first time run by script?
31,880
Solution 1
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
Solution 2
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.
Author by
Sandra
Updated on September 18, 2022Comments
-
Sandra over 1 year
The first time
ssh-copy-id
it will ask# ssh-copy-id -i .ssh/id_dsa.pub [email protected] 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?
-
Sandra over 11 yearsSadly doesn't work, and
ssh-copy-id
doesn't have-o
-
brain99 over 11 yearsWeird, it does report that switch when issuing
ssh-copy-id -?
-
ewwhite over 11 years@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 over 11 yearsAlso, you don't need to specify the key location...
ssh-copy-id servername
works fine. -
Greg Petersen over 11 years
sudo sed -i.bak 's/ssh \$/ssh -o StrictHostKeyChecking=no \$/' $(which ssh-copy-id)
. -
ImranRazaKhan over 4 yearsthere is no -y option