最新消息:20210816 当前crifan.com域名已被污染,为防止失联,请关注(页面右下角的)公众号

【已解决】fabric的Connection出错:paramiko.ssh_exception.AuthenticationException: Authentication failed

出错 crifan 2539浏览 0评论
折腾:
【已解决】Mac中运行fab hello出错:No idea what ‘hello’ is!
期间,去参考官网:
Getting started — Fabric documentation
和:
Welcome to Fabric! — Fabric documentation
试试效果,结果Connection出错:
➜  ~ python
Python 2.7.10 (default, Oct  6 2017, 22:29:07)
[GCC 4.2.1 Compatible Apple LLVM 9.0.0 (clang-900.0.31)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> from fabric import Connection
>>> result = Connection('47.x.x.x').run('uname -s', hide=True)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "<decorator-gen-3>", line 2, in run
  File "/Users/crifan/Library/Python/2.7/lib/python/site-packages/fabric/connection.py", line 29, in opens
    self.open()
  File "/Users/crifan/Library/Python/2.7/lib/python/site-packages/fabric/connection.py", line 541, in open
    self.client.connect(**kwargs)
  File "/Users/crifan/Library/Python/2.7/lib/python/site-packages/paramiko/client.py", line 424, in connect
    passphrase,
  File "/Users/crifan/Library/Python/2.7/lib/python/site-packages/paramiko/client.py", line 714, in _auth
    raise saved_exception
paramiko.ssh_exception.AuthenticationException: Authentication failed.
>>>
结果感觉目标服务器需要验证才能登录
所以报错。
参考:
Getting started — Fabric documentation
fabric2的示例,就不是fabric 1的那种,而是用了Connection去连接远程服务器去操作
而此处,连接服务器又登录出错,所以看看能否解决登录的问题
而此处要连接的服务器,登录不是用密码,而是用密钥。
所以后来自己试了试:
➜  ~ python
Python 2.7.10 (default, Oct  6 2017, 22:29:07)
[GCC 4.2.1 Compatible Apple LLVM 9.0.0 (clang-900.0.31)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> from fabric import Connection
>>> c = Connection(host='47.x.x.x', user='username')
>>> result = c.run('uname -s')
Linux
果然是可以的。
【总结】
此处Fabric 2.x +的版本中的官网示例中用Connection连接远程服务器的话,自己要明确远程服务器连接时的账号和密码或自动加载密钥,确保服务器host可以正常登录,然后再去:
from fabric import Connection
c = Connection(host='47.x.x.x', user='username')
即可正常连接和执行后续操作,比如:
>>> result = c.run('uname -s')
Linux

转载请注明:在路上 » 【已解决】fabric的Connection出错:paramiko.ssh_exception.AuthenticationException: Authentication failed

发表我的评论
取消评论

表情

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址
80 queries in 0.156 seconds, using 22.01MB memory