在python脚本中使用ssh代理

2024-09-30 05:30:06 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在使用python脚本拉入和推入github存储库。对于github存储库,我需要使用ssh密钥

如果在运行脚本之前手动执行此操作:

eval $(ssh-agent -s)
ssh-add ~/.ssh/myprivkey

一切正常,剧本也正常。但是,过了一段时间,密钥显然过期了,我必须再次运行这两个CMD

问题是,如果我在python脚本中使用os.system(cmd)执行此操作,它将不起作用,只有在手动执行此操作时才起作用

我知道使用ssh代理肯定是一种混乱的方式,但我真的不知道它是如何工作的,我只想让脚本工作,仅此而已

脚本每小时运行一次,以防万一


Tags: github脚本cmdadd代理oseval密钥
1条回答
网友
1楼 · 发布于 2024-09-30 05:30:06

正常的方法是在Ssh代理已经运行的shell中运行Python脚本,也可以考虑使用{A1}

的另一种方法。
# This utility will execute the given command (by default, your shell)
# in a subshell, with an ssh-agent process running and your
# private key added to it. When the subshell exits, the ssh-agent
# process is killed.

相关问题 更多 >

    热门问题