Here is my use case: I have a script that lists through hundreds of servers and tests whether or not they allow logins using public key authentication
using a specific private key
(in the ssh client's .ssh
directory). Some of these servers were misconfigured, and I do not have control over the SSH service on any of these servers.
Here is what I have so far:
ssh -o ConnectTimeout=2 -o PasswordAuthentication=no -q $x exit
returncode=$?
So this works so far for most servers (i.e., returns a non-zero
return code when a server is unreachable, and 0
when the server can be logged-in to), until some troublesome server fails due to some SSH misconfiguration (ex. ~/.ssh
on the remote server has an incorrect permission. Here is a related thread describing what can be done in such case.
But i don't want to fix the remote servers. I just want SSH to fail and exit with a non-zero
return code if SSH key authentication
fails.
Any ideas how to get around this?
Thanks in advance.
-o IdentitiesOnly=yes
option – Tagwint Jan 29 '20 at 14:43ssh
(in some circumstances?) asks for password despitePasswordAuthentication=no
and this is the problem. The question body suggests thatssh
in some circumstances fails (returns non-zero exit status) despite the fact the key matches, and this is the problem. In the latter case no password is involved at all. Or do I get it wrong? For now I'm confused, I don't know which problem is the problem. Please [edit] and clarify. – Kamil Maciorowski Jan 29 '20 at 15:41