Reuse in PowerShell a running PuTTY agent (pageant)
I made this work, using the same Cygwin tools (i.e., both ssh-pageant
and Cygwin OpenSSH client) in a PS session.
So I would do (assuming ssh-pageant
is already running from Msys2):
> cd <dir where ssh-pageant is>> .\ssh-pageant -r -a "$env:USERPROFILE\tmp\.ssh-pageant-$env:USERNAME"SSH_AUTH_SOCK='C:\Users\USER1\tmp\.ssh-pageant-USER1'; export SSH_AUTH_SOCK;> $env:SSH_AUTH_SOCK='C:\Users\USER1\tmp\.ssh-pageant-USER1'> .\ssh myserverLogged in to myserver
I have added this to my profile.ps1
(again, it will work when ssh-pageant
is already running when I start the PS session)
$env:MSYS2_DIR=<mydir># Assuming a proxy ssh agent is already running$env:SSH_AUTH_SOCK="$env:MSYS2_DIR\tmp\.ssh-pageant-$env:USERNAME"# We have to make sure we use Msys2 OpenSSH ssh client, not Windows OpenSSH ssh client function ssh_msys2 { & $env:MSYS2_DIR\usr\bin\ssh.exe $args}
If an ssh-pageant
is not yet active, this should work (not tested yet; the PID number may be different):
> cd <dir where ssh-pageant is>> .\ssh-pageant -r -a "$env:USERPROFILE\tmp\.ssh-pageant-$env:USERNAME"SSH_AUTH_SOCK='C:\Users\USER1\tmp\.ssh-pageant-USER1'; export SSH_AUTH_SOCK;SSH_PAGEANT_PID=714; export SSH_PAGEANT_PID;echo ssh-pageant pid 714;> $env:SSH_AUTH_SOCK='C:\Users\USER1\tmp\.ssh-pageant-USER1'> $env:SSH_PAGEANT_PID=714> .\ssh myserverLogged in to myserver
Still have to test a couple of points, and automate the operation.
In particular, executing ssh-pageant
, detecting the PID # if it is returned, and setting environment variable SSH_PAGEANT_PID
from PS if that is the case.This is a little bit more cumbersome than in Msys2, since ssh-pageant
spits something directly executable by bash.