I am trying to write a script that will server more as a health check or security test. I don't need to actually run anything via SSH.
We have a few servers running and for safety reasons we don't always allow SSH to them, and I would like to have a script that I could run that would confirm which are accessible and which are not.
I realize that StackExchange is filled with questions like these, so I quickly found this suggestion:
$ ssh -q user@downhost exit
$ echo $?
255
$ ssh -q user@uphost exit
$ echo $?
0
Basically it would return 255
whenever connection is not possible, but here is where I have an issue. Our servers require a key file AND user/password authentication.
Having BatchMode=yes
I could test it fine if I didn't have the password constraint as well.
I can give the script the location of the file, no problem there. But I get 255
every time because the server requires a password, as can be seen in this answer.
So basically my question is:
Is it possible to write a script that would let me know if it is possible to connect to these servers via SSH (given my constraints), and if it is what would that look like?
I don't need the final script as an answer (although that would be preferable). Just some pointers in the right direction would help me a great deal.
Thanks!