简体   繁体   English

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

[英]How to start ssh-agent permantly with python?

I am looking for the equivalent of eval $(ssh-agent) for python, that will start ssh-agent and will stay running after the script finish to run. 我正在寻找等效于python的eval $(ssh-agent) ,它将启动ssh-agent并在脚本运行完后继续运行。

I didn't find anything useful with Google. 我发现Google没什么用。

I was trying to use that https://pypi.python.org/pypi/ssh-agent-setup/0.2.0 , but it was not working for me. 我正在尝试使用该https://pypi.python.org/pypi/ssh-agent-setup/0.2.0 ,但是它对我不起作用。 Looking at the code on https://github.com/haarcuba/ssh-agent-setup I have found out that is was pretty easy to fix. 查看https://github.com/haarcuba/ssh-agent-setup上的代码,我发现它很容易修复。 I did fork and do a pull request https://github.com/haarcuba/ssh-agent-setup/pull/2 . 我做了分叉并提出了拉取请求https://github.com/haarcuba/ssh-agent-setup/pull/2

For those who are interested in using ssh-agent-setup python module, you can follow the instruction https://github.com/haarcuba/ssh-agent-setup#ssh-agent-setup . 对于那些对使用ssh-agent-setup python模块感兴趣的人,可以按照https://github.com/haarcuba/ssh-agent-setup#ssh-agent-setup的说明进行操作。

If you get: 如果你得到:

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;

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

If anyone wants to implement a something similar the code is pretty easy to understand https://github.com/haarcuba/ssh-agent-setup/blob/master/ssh_agent_setup/ init .py . 如果有人想实现类似的代码,那么代码很容易理解https://github.com/haarcuba/ssh-agent-setup/blob/master/ssh_agent_setup/ init .py

Reading the code, I now understand how ssh-agent can be started in python. 阅读代码,我现在了解了如何在python中启动ssh-agent。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM