This question already has an answer here:
I am trying to achieve a scenario where I need to SSH to ABC server from XYZ server. Public keys will set up already to smooth password less login. Now i just want to exit from script if found that SSH command prompts for password. It means public key are not set up.
ssh -o ConnectTimeout=10 user@ABC <<HERE ----- doing some stuff here---- HERE
Script resides on XYZ. I am running it from XYZ and trying to SSH ABC. If it prompts for password then exit from script by printing a message.