If you're not too picky about remote host authentication...
ssh -o 'StrictHostKeyChecking no' -o 'CheckHostIP no' $host
See man ssh_config
for more details. It can also be handy to use options to set the known_hosts
file to /dev/null
. Otherwise if you're picky it's probably best to manually ssh to all of your destination hosts once and accept the key manually and then failing if you get anything but login / password. It may be even handier to use the -l
option to ssh to specify the login name so you don't have to try and match for the login case. Then you get down to the way my simple scripts of this type work: ssh as a specific user, ignore host key stuff, just wait for password and then the prompt... anything else is a die.