How to use ssh-agent in windows in python?

Fc Zwtyds fczwtyds at gmail.com
Fri May 31 09:57:29 EDT 2019


在 2019-05-31 21:51, Fc Zwtyds 写道:
>> 在 2019-05-30 6:41, Cameron Simpson 写道:
>> ...
>> ...
>> ...
>>> The you could just use os.system() to run the other commands, because 
>>> the environment now has the necessary environment settings.
>>>
>>> See how you go.
>>>
>>> Cheers,
>>> Cameron Simpson <cs at cskk.id.au> (formerly cs at zip.com.au)
> 
> Hi,
>    Under your guidance, the python code using ssh-agent ssh-add has been 
> running successfully. In addition to the code you wrote to me, I also 
> refer to man ssh-agent and subprocess: Subprocess management. I now know 
> the importance of environment variables.
>    This problem has puzzled me for nearly two weeks and solved this 
> problem with your help.
>    With your guidance and help, I have learned a lot. You are a very 
> good teacher. You are my teacher.
> 
> BTW, this program is for visit youtube.
> 
> Cheers!
> 
> Thanks so much.
> 

import subprocess
import os

p = subprocess.Popen('ssh-agent -s', stdin = subprocess.PIPE, stdout = 
subprocess.PIPE, stderr = subprocess.PIPE, shell = True, 
universal_newlines = True)
outinfo, errinfo = p.communicate()
lines = outinfo.split('\n')
for line in lines[:-1]:
     left, right = line.split(';', 1)
     if '=' in left:
         varname, varvalue = left.split('=', 1)
         print(varname + "=" + varvalue)
         os.environ[varname] = varvalue
os.system('ssh-add id_rsa')
os.system('ssh-add -l')

run ok!






More information about the Python-list mailing list