'Try to detect private key type and return paramiko.PKey object.'

def _get_pkey_object(self, key):

    for cls in [paramiko.RSAKey, paramiko.DSSKey, paramiko.ECDSAKey]:
        try:
            key = cls.from_private_key(StringIO(key))
        except paramiko.ssh_exception.SSHException:
            pass
        else:
            return key
    msg = 'Invalid    or    unsupported    key    type    (only    RSA,    DSS    and    ECDSA    keys    are    supported)'
    raise paramiko.ssh_exception.SSHException(msg)
