Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/python
- import paramiko
- jumpHost=paramiko.SSHClient()
- sshKey = paramiko.RSAKey.from_private_key_file('path.to.key/file', password = 'the.passphrase')
- jumpHost.set_missing_host_key_policy(paramiko.AutoAddPolicy())
- jumpHost.connect('jump.hostname',username='foo', pkey = sshKey)
- jumpHostTransport = jumpHost.get_transport()
- dest_addr = ('destination.hostname', 22)
- local_addr = ('jump.hostname', 22)
- jumpHostChannel = jumpHostTransport.open_channel("direct-tcpip", dest_addr, local_addr)
- destHost=paramiko.SSHClient()
- destHost.set_missing_host_key_policy(paramiko.AutoAddPolicy())
- destHost.connect('destination.hostname', username='foo', sock=jumpHostChannel, pkey=sshKey)
- destHostAgentSession = destHost.get_transport().open_session()
- paramiko.agent.AgentRequestHandler(destHostAgentSession)
- stdin, stderr, stdout = destHost.exec_command("my.command.which.connects.to.another.host")
- print(stdout.read())
- print(stderr.read())
- destHost.close()
- jumpHost.close()
Add Comment
Please, Sign In to add comment