【问题标题】:How to start ssh-agent permantly with python?如何使用 python 永久启动 ssh-agent?
【发布时间】:2018-03-31 23:09:29
【问题描述】:

我正在寻找与 eval $(ssh-agent) 等效的 python,它将启动 ssh-agent 并在脚本完成运行后继续运行。

我没有发现任何对 Google 有用的东西。

【问题讨论】:

  • ssh-agent 应该作为系统服务而不是通过 python 运行吗?
  • 我对python不够熟悉,无法直接回答。您在其他语言中想要的将被称为“分离过程”。在 python 中搜索,看看会出现什么
  • 目标是在新机器上自动启动 ssh-agent 以实现测试自动化。

标签: python linux bsd ssh-agent


【解决方案1】:

我试图使用 https://pypi.python.org/pypi/ssh-agent-setup/0.2.0,但它对我不起作用。查看https://github.com/haarcuba/ssh-agent-setup 上的代码,我发现它很容易修复。我做了 fork 并做了一个 pull request https://github.com/haarcuba/ssh-agent-setup/pull/2

对使用 ssh-agent-setup python 模块感兴趣的朋友,可以按照https://github.com/haarcuba/ssh-agent-setup#ssh-agent-setup的说明进行操作。

如果你得到:

ssh_agent_setup.setup()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python3.6/site-packages/ssh_agent_setup/__init__.py", line 34, in setup
    _setupAgent()
  File "/usr/local/lib/python3.6/site-packages/ssh_agent_setup/__init__.py", line 18, in _setupAgent
    raise Exception( 'Could not parse ssh-agent output. It was: {}'.format( process.stdout ) )
Exception: Could not parse ssh-agent output. It was: setenv SSH_AUTH_SOCK /tmp/ssh-thoTQTiOTR0y/agent.47524;
setenv SSH_AGENT_PID 47797;
echo Agent pid 47797;

修复是https://github.com/haarcuba/ssh-agent-setup/pull/2/commits/d262228d379a4c58d357c7d5f83a579ca760e054#diff-39dd5525d88610b0c21a9bec4d2534b0

如果有人想实现类似的东西,代码很容易理解https://github.com/haarcuba/ssh-agent-setup/blob/master/ssh_agent_setup/__init__.py

阅读代码,我现在明白了如何在 python 中启动 ssh-agent。

【讨论】:

    猜你喜欢
    • 2018-01-04
    • 1970-01-01
    • 2021-10-26
    • 1970-01-01
    • 2020-08-26
    • 2019-02-06
    • 2015-05-07
    • 2015-11-20
    • 2013-09-23
    相关资源
    最近更新 更多