在我的 fabfile 中,我已将 env.use_ssh_config 设置为 True。每当我运行 fabfile 时,它都会从 ssh 配置中获取正确的 hostname 和 user,但不是正确的 key 。它会随机通过我的 key (全部存储在 ~/.ssh/中),要求我输入所有 key 的密码,直到找到正确的 key 。
只有 Fabric 让我遇到这个问题。在 fab 文件中将 scp 作为 local 命令运行会使用正确的 key 。
Host example
HostName example.com
User elssar
IdentityFile ~/.ssh/id_example
PreferredAuthentications publickey
我的 ssh 配置中的条目如下所示。
我正在使用 Fabric 1.10.1 和 Paramiko 1.14.1、Python 2.7.3 和 Ubuntu 12.04.
编辑 - 结构存储库中有一个相关的未解决问题 - https://github.com/fabric/fabric/issues/1282
编辑 - 我的 fabfile 的基本结构,以及我如何运行它
from fabric.api import env, run
def do_something():
run("echo test")
def setup(host):
env.hosts = [host]
# command
fab server:hostname do_something
请您参考如下方法:
我试图检查我的设置;这是我所做的调试:
>>> from fabric.network import key_filenames
>>> key_filenames()
[]
>>> from fabric.state import env
>>> env.use_ssh_config = True
>>> env.host_string = 'salt-states'
>>> key_filenames()
['/Users/damien/.ssh/salt.rsa.priv']
更新:您可以更新您的 fabfile 以检测您的任务:
from fabric.api import env, run
from fabric.network import key_filenames
def do_something_debug():
env.use_ssh_config = True
print key_filenames()
run("echo test")
def server(host):
env.hosts = [host]
然后运行命令
fab server:hostname do_something_debug
