Python Fabric gives: Fatal error: No existing session

verbatim picture verbatim · Mar 9, 2011 · Viewed 8.2k times · Source

I have the following simple fabfile.py from the docs:

from fabric.api import run

def host_type():
    run('uname -s')

I try to run it using:

fab -H 192.168.0.201 host_type

But get the error:

me@ubuntu:~/me$ fab -H 192.168.0.201 host_type
[192.168.0.201] run: uname -s
Password for [email protected]: 

Fatal error: No existing session

Aborting.

I can ssh okay into 192.168.0.201.

Any ideas?

Answer

Troy J. Farrell picture Troy J. Farrell · Nov 7, 2012

Short answer: try the '-k' and '-a' command-line flags if you have more than one SSH public key and want to use password authentication.

When I encountered this error, it was the result of a very unique situation. I have many different public keys in ~/.ssh. I also have many of those public keys added to my SSH agent. I was attempting to use Fabric with only a password.

Here's what I saw in the server authentication logs:

Nov  7 07:56:02 ubuntu sshd[1862]: Disconnecting: Too many authentication failures for user [preauth]
Nov  7 07:56:08 ubuntu sshd[1864]: Disconnecting: Too many authentication failures for user [preauth]

I had instructed Fabric to use not public keys for authentication with the '-k' command-line flag. I had missed that Fabric (via Paramiko) defaults to using whatever is available via the SSH agent. In my case, all these public keys were registered with the SSH agent, so telling Fabric not to use public keys was an incomplete solution. I added the '-a' command-line flag which tells Fabric not to query the SSH agent. Finally, I could use password authentication to connect to the server with Fabric.