def get_ssh_key_for_host(host):
ssh_config = paramiko.SSHConfig()
user_config_file = os.path.expanduser("~/.ssh/config")
if os.path.exists(user_config_file):
with open(user_config_file) as f:
ssh_config.parse(f)
user_config = ssh_config.lookup(host)
if 'identityfile' in user_config:
path = os.path.expanduser(user_config['identityfile'][0])
if not os.path.exists(path):
raise Exception("Specified IdentityFile "+path
+ " for " + host + " in ~/.ssh/config not existing anymore.")
return path
评论列表
文章目录