If your python script may need to start an ssh-agent, this script sets up the environment according to the bourne-shell commands returned from that command on stdout.
1 2 3 4 5 6 7 8
import os import re def ssh_attach(ssh_agent_cmd): sh_cmds=os.popen(ssh_agent_cmd).readlines() for sh_line in sh_cmds: matches=re.search("(\S+)\=(\S+)\;", sh_line) os.environ[matches.group(1)]=matches.group(2)
I have some test control scripts that start ssh sessions all over the place. Normally, my PuTTY agent on my PC forwards its authentication to these machines. Instead of running ssh-agent, one can use scripts like that at http://www.hackinglinuxexposed.com/tools/find-ssh-agent/src/find-ssh-agent to attach to an existing ssh agent.