0

I am trying to create some script which will periodically check some page, find some information, and based on that clone for me some repository (doesn't matter what and why).

The way I am trying to do is:

env = os.environ.copy()
subprocess.Popen(['git clone <REPO>'], stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True, env=env, cwd='mydir')

This works fine when I start this script from a normal shell. However, when I add it to cron, it fails with a "Permission denied publickey" error.

The issue is with my keys added to ssh_agent, that is why I copy all envs and pass it to Popen, and use shell=True. I thought this subshell would use the environments that I pass, including ssh_agent PID, and be able to communicate with it and get my key. But it doesn't happen. Why? Do you know how to resolve this? I really want this to work from cron.

UPDATE: I got redirected to some other questions suggesting using keychain. Thanks, I will check it out. But in the meantime I gave it a shot one more time with changing this line:

env = os.environ.copy()

to:

env = { 'SSH_AUTH_SOCK': '/run/user/643752548/keyring/ssh'}

and this worked fine from cron also!

However, this is not a good solution, as I would have to change the script every time I relog on my computer. So anyway I will check out the keychain solution.

YotKay
  • 989
  • 1
  • 7
  • 24

0 Answers0