def ssh_connect(cf):
"""
this is adapted from code by Sebastian Dahlgren
http://sebastiandahlgren.se/2012/10/11/using-paramiko-to-send-ssh-commands/
"""
try:
ssh = paramiko.SSHClient()
ssh.load_system_host_keys()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh.connect(cf.server,username=cf.username)
print("Connected to %s" % cf.server)
except paramiko.AuthenticationException as e:
print("Authentication failed when connecting to %s" % cf.server)
print("error:",e)
sys.exit(1)
except Exception as e:
print("Couldn't establish an ssh connection to %s" % cf.server)
print("error:", e)
sys.exit(1)
return ssh
评论列表
文章目录