折腾:
【已解决】Mac中运行fab hello出错:No idea what ‘hello’ is!
期间,去参考官网:
和:
试试效果,结果Connection出错:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | ➜ ~ 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. >>> |
结果感觉目标服务器需要验证才能登录
所以报错。
参考:
fabric2的示例,就不是fabric 1的那种,而是用了Connection去连接远程服务器去操作
而此处,连接服务器又登录出错,所以看看能否解决登录的问题
而此处要连接的服务器,登录不是用密码,而是用密钥。
所以后来自己试了试:
1 2 3 4 5 6 7 8 | ➜ ~ 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可以正常登录,然后再去:
1 2 | from fabric import Connection c = Connection(host = '47.x.x.x' , user = 'username' ) |
即可正常连接和执行后续操作,比如:
1 2 | >>> result = c.run( 'uname -s' ) Linux |
转载请注明:在路上 » 【已解决】fabric的Connection出错:paramiko.ssh_exception.AuthenticationException: Authentication failed