2017-02-20 6 views
0

jumphost를 통해 원격 시스템으로 ssh를 보내야합니다.paramiko를 사용하여 ssh-agent를 여러 홉으로 추가하는 방법

내가 같이 할 SSH를 사용하여 : 난 그냥 몇 가지 명령을 실행하려면 SSH -A -t 사용자 @ jumphost ssh를 -A 사용자 @의 vm_to_login

을, 내가 실행 SSH를 -A -t 사용자 @ 난 그냥 생각 ... 내가 위의 스크립트를 실행할 때

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) 

, 프로그램이 무한 시간 걸려 : jumphost SSH -A 사용자 @의 vm_to_login는

지금 내가이 사용하는 파이썬을하고 시도 "명령을 실행합니다" SSHClient 객체는 키를 추가 할 수 없습니다. ssh 에이전트와 두 번째 서버가 키를 찾을 때 키 요청은 점프 박스로 이동하고 점프 박스에서 일부는 내 로컬로 이동하지만 SSHClient 객체에는 해당 키가 있습니다.

더 많은 정보가 필요하면 알려 주시기 바랍니다.

답변

0

나는 위의 프로그램 사용자를 사용하기 전에 paramiko

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) 
    s = ssh_client.get_transport().open_session() 
    # set up the agent request handler to handle agent requests from the server 
    paramiko.agent.AgentRequestHandler(s) 
    return ssh_client 

를 사용하여 에이전트 전달을 처리하는 방법에 대한 해답을 가지고 올바른 개인 키는 ssh를 에이전트를 추가되었는지 확인한다. 호스트에서 다음 명령을 실행하여 ssh-agent에 개인 키를 추가하십시오 : 1. eval $ (ssh-agent) 2. ssh-add [개인 키의 경로. ex - ~/.ssh/id_rsa]