6

I'm trying to connect to host and run command with module Fabric 2 and have this error:

Traceback (most recent call last):
  File "Utilities/fabfile.py", line 4, in <module>
    res.run('uname -s')
  File "<decorator-gen-3>", line 2, in run
  File "/usr/local/lib/python2.7/dist-packages/fabric/connection.py", line 29, in opens
    self.open()
  File "/usr/local/lib/python2.7/dist-packages/fabric/connection.py", line 501, in open
    self.client.connect(**kwargs)
  File "/home/trishnevskaya/.local/lib/python2.7/site-packages/paramiko/client.py", line 424, in connect
passphrase,
  File "/home/username/.local/lib/python2.7/site-packages/paramiko/client.py", line 715, in _auth
raise SSHException('No authentication methods available')
paramiko.ssh_exception.SSHException: No authentication methods available

Simple code from docs (http://docs.fabfile.org/en/latest/getting-started.html):

from fabric import Connection

res = Connection('<host-ip>')
res.run('uname -s')

Accoding to docs, I don't need in special configs, but it's doesn't work...

fabric 2.1.3
python 2.7.14

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
Ameko
  • 63
  • 2
  • 4
  • Possible duplicate of [SSH - Python with paramiko issue](https://stackoverflow.com/questions/14326665/ssh-python-with-paramiko-issue) – Patrick Artner Jun 06 '18 at 05:16
  • or [using-an-ssh-keyfile-with-fabric](https://stackoverflow.com/questions/5327465/using-an-ssh-keyfile-with-fabric) – Patrick Artner Jun 06 '18 at 05:29

2 Answers2

9

Following works for me.

connect_kwargs = {"key_filename":['PATH/KEY.pem']}
with Connection(host="EC2", user="ubuntu", connect_kwargs=connect_kwargs) as c:
    c.run("mkdir abds")
Ishan Bhatt
  • 9,287
  • 6
  • 23
  • 44
4

I run into the same issue. Rather than passing a SSH keyfile, as suggested previously, another trivial way to sort it out might be to pass a password (that would be fine just over the test/development stage).

import getpass
from fabric import Connection, Config
sudo_pass = getpass.getpass("What's your user password?\n")
config = Config(overrides={'user': '<host-user>', 'connect_kwargs': {'password': sudo_pass}})
c = Connection('<host-ip>', config=config)
c.run('uname -s')
dbrus
  • 79
  • 1
  • 3