Is there a way to programmatically test whether ssh can authenticate using a public key? I would like to do something like this (preferably in bash, but am open to a python solution):
ssh-test-thingy user@host || echo "could not authenticate using publickey"
where ssh-test-thingy
returns a non-zero exit status if no public key matches on the remote host.