问题
We currently run a script on our desktop that uses paramiko to ssh to a remote linux host. Once we are on the remote linux host we execute another command to log into another remote machine. What we want to do is from paramiko pass the keys to the remote server so we can use them again to ssh to another remote host.
This would be the equivalent functionality of 'ssh -A remotehost.com' in linux.
回答1:
You can enable SSH agent forwarding for a session in paramiko using AgentRequestHandler. To do this, call paramiko.agent.AgentRequestHandler(s)
with the session s
. For example:
client = paramiko.client.SSHClient()
client.connect(host, port, username)
s = client.get_transport().open_session()
paramiko.agent.AgentRequestHandler(s)
See this post for more details and code.
来源:https://stackoverflow.com/questions/23666600/ssh-key-forwarding-using-python-paramiko