def _checkAccessUsingKey(self, host, user, port=SSH_DEFAULT_PORT):
"""
check if we have SSH access via user by using SSH keys ?
Having an AuthenticatioException is one of the standard ways.
:param Lab host: hostname
:param str user: user to login
:return: None if no connection. Returns instance of SSH connection if OK
:rtype: None/object
>>> self._checkAccessUsingKey(host, user, port=SSH_DEFAULT_PORT)
"""
#client = paramiko.SSHClient()
client = paramiko.client.SSHClient()
client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
# to ignore user .ssh homedir keys : use those options allow_agent=False, look_for_keys=False)
# CAUTION with those option : exception is SSHException (instead of AuthenticationException)
client.connect(host, port, user, key_filename=self.privateKey)
client.get_transport().set_keepalive(self.__class__.defaultHeartbeat)
return client
评论列表
文章目录