How to use ssh-agent in windows in python?

Fc Zwtyds fczwtyds at gmail.com
Sun May 26 20:22:48 EDT 2019


在 2019-05-27 7:13, Cameron Simpson 写道:
> On 26May2019 22:55, Fc Zwtyds <fczwtyds at gmail.com> wrote:
>>  I am using cygwin on Windows 8.1. These two commands work fine in 
>>  cygwin:
>> ssh-agent -s
>> ssh-add ~/.ssh /id_rsa
> 
> No, they run without error (apparently). That is  an entirely different 
> thing.
> 
> In particular, "ssh-agent -s" starts an agent but unless you make use of 
> its output, your subsequent commands will have no idea how to access it.
> 
> Since ssh-add (apparently) works, then I would guess you _already_ had 
> an agent, and it is adding to that agent's keys. And, importantly, 
> _ignoring_ the new agent you started.
> 
> Try running your commands above again, but _before_ them, run "ssh-add 
> -l". If that works then there's already an agent known to the shell and 
> your subsequent "ssh-add" is likely adding to that, not to the new agent 
> you dispatched.
> 
>>  I tried to use them on windows cmd and it worked fine. Now I am going 
>> to use python to write code to implement the above command.
>> os.system('ssh-agent -s')
>> os.system('ssh-add id_rsa')
>> There was an error:
>> Could not open a connection to your authentication agent.
> 
> I'm presuming that as with UNIXy systems, os.system() on Windows issues 
> its commands to a distinct shell ( instance of cmd.exe or the like).
> 
> As such, since you've made no effort to catch and parse the output of 
> "ssh-agent -s" you don't know how to talk to the agent you started, and 
> further since you don't pass any information to the shell running 
> "ssh-add" then it doesn't know how to do that either.
> 
> Cheers,
> Cameron Simpson <cs at cskk.id.au>

Thank you very much for your detailed answer.
I will try to learn how to capture and parse the output of "ssh-agent 
-s" and learn how to talk to the agent.




More information about the Python-list mailing list