简体   繁体   English

使用python paramiko进行SSH密钥转发

[英]SSH Key-Forwarding using python paramiko

We currently run a script on our desktop that uses paramiko to ssh to a remote linux host. 当前,我们在桌面上运行脚本,该脚本使用paramiko SSH到远程Linux主机。 Once we are on the remote linux host we execute another command to log into another remote machine. 在远程Linux主机上后,我们将执行另一个命令以登录另一台远程计算机。 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. 我们想要做的是从paramiko将密钥传递到远程服务器,以便我们可以再次使用它们将ssh传递到另一个远程主机。

This would be the equivalent functionality of 'ssh -A remotehost.com' in linux. 这将是Linux中“ ssh -A remotehost.com”的等效功能。

You can enable SSH agent forwarding for a session in paramiko using AgentRequestHandler . 您可以使用AgentRequestHandler为paramiko中的会话启用SSH代理转发。 To do this, call paramiko.agent.AgentRequestHandler(s) with the session s . 为此,请使用会话s调用paramiko.agent.AgentRequestHandler(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. 有关更多详细信息和代码,请参见此帖子

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM