I have this small script for connecting to new machines I don't have ssh-key to:
function my_ssh () {
ip=$1
optional_cmd=$2
ssh -o "BatchMode yes" user_name@$ip exit > /dev/null 2>&1
if [ $? -gt 0 ]; then
echo "1st time connection - adding key to authorized keys list"
sshpass -p "secret_password" ssh-copy-id user_name@$ip
fi
echo $optional_cmd
ssh -X user_name@$ip $optional_cmd
}
This works weel for servers that either have my ssh-key, or only ask for a password in order to use ssh-copy-id. However, some servers require a "yes/no" after the following question:
The authenticity of host 'A.B.C.D ()' can't be established. ECDSA key fingerprint is SHA256:****. Are you sure you want to continue connecting (yes/no)?
How can I add a "yes" string echoed into the server question stdin and then use the sshpass?
ps, I went over the sshpass code from github but it doesn't seem sshpass
is designed for something like this. I think I can modify it to suite my needs, but I prefer using a normal Linux mechanism if possible
ssh-copy-id -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null ...