如何使用 python 永久启动 ssh-agent?

How to start ssh-agent permantly with python?

我正在为 python 寻找 eval $(ssh-agent) 的等效项,它将启动 ssh-agent 并在脚本完成后保持 运行ning 到 运行。

我没有发现 Google 有任何用处。

我正在尝试使用那个 https://pypi.python.org/pypi/ssh-agent-setup/0.2.0, but it was not working for me. Looking at the code on https://github.com/haarcuba/ssh-agent-setup I have found out that is was pretty easy to fix. I did fork and do a 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了。