如何解决在 python 脚本中使用 ssh 代理
我正在使用 python 脚本拉取并推送到 github 存储库。对于 github 存储库,我需要使用 ssh 密钥。
如果我在运行脚本之前手动执行此操作:
eval $(ssh-agent -s)
ssh-add ~/.ssh/myprivkey
一切正常,脚本正常。但是,过了一会儿,显然密钥过期了,我必须再次运行这两个 cmds
问题是,如果我在 python 脚本中使用 os.system(cmd)
执行此操作,则它不起作用,只有当我手动执行此操作时才有效
我知道这一定是使用 ssh 代理的一种混乱方式,但老实说我不知道它是如何工作的,我只是想让脚本工作,仅此而已
脚本每小时运行一次,以防万一
解决方法
虽然通常的方法是在 ssh 代理已经运行的 shell 中运行您的 Python 脚本,但您也可以考虑使用 sshify.py
# 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.
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。