【问题标题】:When I run my fabfile, I am being asked for password although I specified a key. Why?当我运行我的 fabfile 时,我被要求输入密码,尽管我指定了一个密钥。为什么?
【发布时间】:2018-07-27 00:27:17
【问题描述】:

我有一个运行 fabfile 的 python 脚本。我的问题是,每当我从脚本运行 fabfile 时,都会要求我输入密码。但是,即使我使用相同的 fab 参数,当我从命令行手动运行 fabfile 时,登录也可以使用指定的密钥正常工作。这是我的 fabfile 的内容:

[root@ip-10-10-20-82 bakery]# cat fabfile.py
from fabric.api import run

def deploy():
    run('wget -P /tmp https://s3.amazonaws.com/LinuxBakery/httpd-2.2.26-1.1.amzn1.x86_64.rpm')
    run('sudo yum localinstall /tmp/httpd-2.2.26-1.1.amzn1.x86_64.rpm')

这是我在命令行上成功使用的语法:

fab -u ec2-user -i id_rsa -H 10.10.15.185 deploy

这是一段 python 代码,由于某种原因提示输入密码而不是使用密钥:

import subprocess
subprocess.call(['fab', '-f', '/home/myhome/scripts/bakery/fabfile.py', '-u ec2-user', '-i', '/home/myhome/scripts/bakery/id_rsa', '-H', bakery_internalip, 'deploy'])

这是我运行它时发生的情况:

[10.10.15.185] Executing task 'deploy'
[10.10.15.185] run: wget -P /tmp https://s3.amazonaws.com/LinuxBakery/httpd-2.2.26-1.1.amzn1.x86_64.rpm
[10.10.15.185] Login password for ' ec2-user':

【问题讨论】:

    标签: python ssh fabric


    【解决方案1】:

    你可以使用ssh-agent:

    $ eval `ssh-agent -s`
    $ ssh-add /home/myhome/scripts/bakery/id_rsa
    $ fab -H 10.10.15.185 deploy
    

    【讨论】:

      【解决方案2】:

      即使我指定了密钥,系统仍要求我输入密码,因为“u”和“ec2-user”之间有一个额外的空格。这是之前的sn-p:

      '-u ec2-user'
      

      这是之后:

      '-uec2-user'
      

      额外的空间意味着 fab 正在尝试使用“ec2-user”而不是“ec2-user”进行身份验证。

      【讨论】:

        猜你喜欢
        • 2017-07-04
        • 2014-12-11
        • 1970-01-01
        • 2020-01-08
        • 2015-02-27
        • 2020-12-20
        • 1970-01-01
        • 1970-01-01
        • 2021-11-24
        相关资源
        最近更新 更多