A small correction: to overcome the expected approach to a remote server, it is required, but if a local script connects to a group of remote servers, what configuration may be broken, just use the SSH parameters:
ssh -f -q -o BatchMode=yes -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null USER@TARGETSYSTEM
This will skip the password request, if there is no ssh_key setting, exit silently and continue using script / other hosts.
Places ssh in the background code with -f, which is required when the ssh command is called from the sh (batch) file to remove the local console with redirection to remote login (implies -n).
source share