Reputation: 31
I am trying to write a python script to execute a number of remote commands on a linux machine from Windows. I am using paramiko as the SSH connection library and running some fab scripts on the remote machine.
However, the fab scripts then connect to other machines so I need to use agent forwarding. However, whenever I run the code I get this error:
Exception in thread Thread-3:
Traceback (most recent call last):
File "C:\Python27\lib\threading.py", line 801, in __bootstrap_inner
self.run()
File "C:\Python27\lib\site-packages\paramiko\agent.py", line 117, in run
raise AuthenticationException("Unable to connect to SSH agent")
I have copied verbatim several examples including: https://gist.github.com/toejough/436540622530c35404e6
It looks like I need to set up a local authentication agent as it is just forwarding to nothing, but I can't find out how to do that.
My code:
privkey = paramiko.RSAKey.from_private_key_file(PrivKeyDirFile, password = PrivKeyPw)
# Start the client
client = paramiko.client.SSHClient()
client.set_missing_host_key_policy(paramiko.client.AutoAddPolicy())
client.load_system_host_keys()
client.connect(hostname = Host, username = User, pkey = privkey)
# get a session
sshChannel = client.get_transport().open_session()
# set up the agent request handler to handle agent requests from the server
paramiko.agent.AgentRequestHandler(sshChannel) # <--UNDOCUMENTED??!!
# get a shell
sshChannel.get_pty()
sshChannel.invoke_shell()
# SNIP
sshChannel.send
("command-which-invokes-fab-script\n")
# error now happens
Please help!
Upvotes: 2
Views: 875
Reputation: 21486
Maybe I'm just too much a novice with SSH/paramiko, but I'm confused by everything starting on the line
# get a session
Why not just have:
# Connect the client as before ...
# Run the command:
stdin, stdout, stderr = client.exec_command('command-which-invokes-fab-script', get_pty = True)
Upvotes: 0