0
我需要通过jumphost ssh到远程机器。使用ssh使用paramiko如何将ssh密钥添加到ssh-agent多跳中
我这样做: SSH -A -t用户@ jumphost SSH -A用户@ vm_to_login
,如果我只是想运行一些命令,我运行: SSH -A -t用户@ jumphost SSH -A用户@ vm_to_login“命令来执行”
现在我试着这样做使用python:
def ssh_connect(jumphost_ip):
ssh_client=paramiko.SSHClient()
ssh_client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
path_to_key=os.path.join(os.environ['HOME'], '.ssh', 'id_rsa')
ssh_client.connect(jumphost_ip, username='vagrant', key_filename=path_to_key, allow_agent=True)
return ssh_client
ssh_client = ssh_connect(host_ip)
stdin, stdout, stderr = ssh_client.exec_command("""ssh [email protected]_to_run_command -A "docker network inspect --format '{{json .Containers }}' bridge" """, get_pty=True)
当我运行上面的脚本,程序挂无限的时间..我只是猜测SSHClient对象无法将密钥添加到ssh代理,当第二台服务器查找密钥时,密钥请求会转到跳转框,并从jumpbox跳到我的本地,但SSHClient对象确实有这些密钥。
如果需要更多信息,请让我知道。