Firstly I tried to get fabric working, but it kept asking me for a password.
So I’m trying to reduce the problem. Perhaps it would be a good POC to just create a SSH connection from Python. I discovered that fabric uses parmiko for it’s SSH handling. Hmm. Ok, lets try to get an example working.
Here’s what I wrote.
from ssh import *
import os
print "SSH-AGENT VARS"
print "SSH_AGENT_PID: %s " % os.environ['SSH_AGENT_PID']
print "SSH_AUTH_SOCK: %s " % os.environ['SSH_AUTH_SOCK']
a = Agent()
keys=a.get_keys()
print keys.count("192.168.1.10")
client = SSHClient()
client.load_system_host_keys()
client.connect('192.168.1.10')
Resulting in the following error messages:
% ./ssh_test.py
SSH-AGENT VARS
SSH_AGENT_PID: 26557
SSH_AUTH_SOCK: /tmp/ssh-pZHBElj26556/agent.26556
0
Traceback (most recent call last):
File "./ssh_test.py", line 18, in <module>
client.connect('192.168.1.10')
File "/usr/local/lib/python2.7/dist-packages/ssh/client.py", line 332, in connect
self._auth(username, password, pkey, key_filenames, allow_agent, look_for_keys)
File "/usr/local/lib/python2.7/dist-packages/ssh/client.py", line 493, in _auth
raise saved_exception
ssh.PasswordRequiredException: Private key file is encrypted
ssh-agent is running in my session, I can SSH to that box, no problems, it doesn’t prompt me for a password or anything.
I’m guessing paramiko isn’t able to connect to the running ssh-agent for some weird reason.
Has anyone else had a problem like this? I’m using Ubuntu 11.10
I seem to remember trying Fabric a while back and having similar problems, perhaps it’s been broken for a while?
I connect, just using the host name as the argument. This is as per the documentation.
http://www.lag.net/paramiko/docs/paramiko.SSHClient-class.html
connect(self, hostname, port=22, username=None, password=None, pkey=None, key_filename=None, timeout=None, allow_agent=True, look_for_keys=True, compress=False)
Ok, so the first thing I discovered was that Paramiko is way out of date, and unmaintained.
It’s now known as package ssh, at least under Ubuntu, and has a different maintainer (bitprophet)
Here’s a demo class that works exactly as described:
https://raw.github.com/bitprophet/ssh/master/demos/demo.py
It requires this file, for interactive prompts:
https://github.com/bitprophet/ssh/blob/master/demos/interactive.py
Here’s a sample session, using it:
That doesn’t answer the question of why fabric isn’t authenticating against the ssh-agent correctly thought. So the question remains open.
Update:
Thanks to Morgan’s hint, I’ve gotten a little further with this problem. As he suggested, I enabled ssh logging by adding the following to the top of my fabfile.py
I also monitored the server log. In doing so I discovered that the user which I specified was being disregarded and my local username used instead.
On the server:
Locally:
Hmm, that’s strange, I ran the command as:
fab diskfree -H xxx.xxx.xxx.xxx -u root
But what is this?
Hmm
Could that be the root of the problem? Could the ssh error messages just be misleading me?
I removed the line and it worked, so I guess so, is the answer.