python Fabric和ssh-agent,请参阅https://www.leepa.io/2010/11/09/fabric-and-ssh-agent-aka-running-git-in-f

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了python Fabric和ssh-agent,请参阅https://www.leepa.io/2010/11/09/fabric-and-ssh-agent-aka-running-git-in-f相关的知识,希望对你有一定的参考价值。

def _shell_escape(string):
    """ Escape double quotes, backticks and
    dollar signs in given ``string``.

    For example:

    >>> _shell_escape('abc$') 'abc\\\\$'
    >>> _shell_escape('"') '\\\\"'
"""
    for char in ('"', '$', '`'):
        string = string.replace(char, '\%s' % char)
    return string

def sshagent_run(cmd, shell=True):
    """ Helper function. Runs a command with SSH agent forwarding enabled.

    Note:: Fabric (and paramiko) can't forward your SSH agent. This helper uses
    your system's ssh to do so. """

    real_command = cmd

    # We have to grab the env['cwd'] and then munge it blank
    # otherwise the call to local() will not run as it'll try and
    # do a local cd - that is not desired.
    cwd = env.get('cwd', '') env['cwd'] = ''

    if shell:
        # Handle cwd munging via 'cd' context manager
        cwd_cmd = ''
        if cwd:
          cwd_cmd = 'cd %s && ' % _shell_escape(cwd)
        # Construct final real, full command
        real_command = '%s \\"%s\\"' % (env.shell, _shell_escape(cwd_cmd + real_command))

    print("[%s] sshagent_run: %s" % (env.host_string, cmd))

    try:
        print local('ssh -p %s -A %s@%s "%s"' % (env.port, env.user, env.host, real_command), capture=False)
    except ValueError, v:
        print v
    finally:
        # Put the cwd back if needed
        env['cwd'] = cwd

以上是关于python Fabric和ssh-agent,请参阅https://www.leepa.io/2010/11/09/fabric-and-ssh-agent-aka-running-git-in-f的主要内容,如果未能解决你的问题,请参考以下文章

sh 确保ssh-agent正在运行并且您设置了正确的env变量(如果可能,请重新使用)

自动化运维工具fabric的简明使用手册

python 以递归方式收集所有* .ppk,启动PAGEANT.EXE(Windows的ssh-agent)

python自动化管理sshy(ssh,ssh-copy-id,ssh-agent)

python自动化管理sshy(ssh,ssh-copy-id,ssh-agent)

ssh-agent 没有在 CMD 中创建 [重复]