Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SSH Key-Forwarding using python paramiko

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.

like image 769
user2909250 Avatar asked May 14 '14 23:05

user2909250


People also ask

How do I enable SSH key forwarding?

From the configuration, go to Connection > SSH > Auth and enable “Allow agent forwarding.” You can also add your private key file from the same pane. PuTTY will handle the SSH agent for you, so you don't have to mess around with any config files.

What is the use of Paramiko module in Python?

Paramiko is a Python library that makes a connection with a remote device through SSh. Paramiko is using SSH2 as a replacement of SSL to make a secure connection between two devices. It also supports the SFTP client and server model.

What is Paramiko transport?

An SSH Transport attaches to a stream (usually a socket), negotiates an encrypted session, authenticates, and then creates stream tunnels, called channels , across the session. Multiple channels can be multiplexed across a single session (and often are, in the case of port forwardings).


1 Answers

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.

like image 85
aousterh Avatar answered Sep 20 '22 00:09

aousterh