Search code examples
securitysshmonitoringopenssh

How can I programmatically detect ssh authentication types available?


I'd like to write a monitoring plugin that checks various hosts on my network to make sure that password or interactive SSH authentication is not enabled. That is, I need to write code that:

  1. Connects to an SSH port.
  2. Enumerates available authentication methods.
  3. Verifies that only key based authentication is possible.

Methods using either python or bourne sh code (using ssh) is most interesting to me, but other languages, libraries or hints are appreciated too.


Solution

  • I'm currently building one myself, however, you can force ssh to output (to STDERR) the supported methods by using the PreferredAuthentications option. This can easily be parsed with grep/python/language of choice.

    HostA$ ssh -o PreferredAuthentications=none HostB
    Permission denied (publickey,gssapi-with-mic).
    HostA$ ssh -o PreferredAuthentications=none HostC
    Permission denied (publickey,gssapi-with-mic,password,keyboard-interactive,hostbased).