【发布时间】:2014-09-04 18:51:45
【问题描述】:
我正在使用subprocess.Popen 实例化ssh-agent,添加密钥并将git 存储库推送到远程。为此,我将它们与&& 串在一起。我使用的代码是
subprocess.Popen("eval $(ssh-agent) && ssh-add /root/.ssh/test_rsa && git push target HEAD", shell=True)
当我将其作为.py 文件运行时,系统会提示我输入密钥的密码。这似乎可以正常工作。
Identity added: /root/.ssh/test_rsa (/root/.ssh/test_rsa)。
但是当它尝试将存储库推送到远程时,会发生错误。
ssh: connect to host ***.***.***.*** port 22: Connection refused
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
但是,如果我只是在交互式 shell 中运行相同的命令,它就可以工作。是什么导致了这种行为差异,我能做些什么来解决这个问题?
【问题讨论】:
-
向我们展示您的 Python 代码,并请告诉我们您是在 Python 中以交互方式运行该代码,还是工作版本直接在(非 Python)终端中。
-
谢谢,进行了编辑。工作版本在交互式 shell 中。
标签: python linux git shell ssh