ndbeals/winssh-pageant

Trouble using with Cygwin and ssh-pageant

Closed this issue · 6 comments

So I thought I could be clever and use winssh-pageant along with ssh-pageant. I have to use scripts that only work with rsync in Cygwin. I've used pageant before along with ssh-pageant running in Cygwin and then did all my ssh stuff in Cygwin. I was hoping to make it so I could use the exact same settings across all my windows apps and processes by chaining:

ssh (Cygwin) -> ssh-pageant -> winssh-pageant -> ssh-ageant (OpenSSH on Windows)

I was trying to look at options for both proxies but there doesn't seem to be much to tweak. I assume it is a problem with how ssh-pageant talks with pageant not being compatible with winssh-pageant.

My setup:

  • symbolic link my win ~/.ssh directory to my cygwin ~/.ssh so both environments use the same keys and ssh config
  • added my key to ssh-ageant in windows using ssh-add
  • running winssh-pageant
  • confirmed can auto sign in to remote server using WinSCP (verifies winssh-pageant is working)
  • installed ssh-pageant in Cygwin and have it start at shell startup
  • try to SSH in Cygwin but instead get prompted for passphrase

Just so I'm covering all my bases. Using pageant.exe that comes with WinSCP the ssh-pageant on the Cygwin side works. I have WinSCP version 5.19.1 installed.

I find it interesting that:

  • WinSCP is working with winssh-pageant
  • ssh-pageant is not working with winssh-pageant
  • ssh-pageant does work with pageant (bundled with WinSCP which does work with winssh-pageant)

Looks like my console gets some output when I run it (even though I can execute other commands)? Not super useful log.

In Cygwin I launch, ssh-pageant seems to start up, then I try SSH:

ssh-pageant pid 1959

me@desktop ~
$ ssh server
Enter passphrase for key '/home/me/.ssh/id_rsa':

After it fails and promps me for passcode in the console on Windows side this prints out:

2022/07/05 16:38:30 cannot read from pipe \\.\pipe\openssh-ssh-agent: EOF

Hey @immersivegamer sorry for the delayed response, I just wanted to let you know I am looking into this, no ETA yet though

This problem is the same (I think) as #18, It's actually been on my radar for a bit, this bumps the priority

I believe @ndbeals is correct. This is the same as #18. Although not forcefully stated but implied in https://github.com/git-for-windows/git/wiki/OpenSSH-Integration-with-Pageant

Quoting the webpage:

-a filename -- Bind to a specific socket file (creating it if necessary)
-r -- Allow reuse of an existing socket file (exit without error if an existing ssh-pageant/ssh-agent process is using it)
It mentions "socket file".

I am sure that Windows pipe can't be used. I've tried it with wsl_ssh_pageant which requires SSH_AUTH_SOCK to be set to a pipe.

Quoting the webpage:

NOTE: Since there can only be a single global variable of a given name, this approach may or may not cause conflicts if you have multiple environments which utilize the SSH_AUTH_SOCK setting. Running Git alongside of Cygwin, or MSYS2, for example. One way to address this is to use a fully-qualified Windows path for the socket instead of an environment-specific Unix/MSYS2 path.

Again, using a file is implied here.

I only use GIT Bash and not any of the others and I have this in my .bashrc file:

SSH_PAGEANT="$(command -v ssh-pageant)"
if [ -x "$SSH_PAGEANT" ]; then
eval $("$SSH_PAGEANT" -qra "${TEMP:-/tmp}/.ssh-pageant-$USERNAME}")
fi

So my Windows value of SSH_AUTH_SOCK is set to \.\pipe\ssh-pageant
and my GIT Bash SSH_AUTH_SOCK is set to /tmp/.ssh-pageant-userID

Everything works with standard Pageant software and IF winssh-pageant emulates PuTTY's pageant closely, it should also work for you.

For some reason the eval statement isn't displaying properly ?!?

I've added spaces here to see if that helps

eval $ ( " $ SSH_PAGEANT" -qra "$ {TEMP:-/tmp}/.ssh-pageant-$USERNAME}")

Thanks for the information @dvhsfan, following those steps I was able to get ssh-pageant working with my tool.

@immersivegamer here's the configuration you need to add to your .bashrc

# ssh-pageant allows use of the PuTTY authentication agent (Pageant)
SSH_PAGEANT="$(command -v ssh-pageant)"
if [ -x "$SSH_PAGEANT" ]; then
   eval $("$SSH_PAGEANT" -qra "${SSH_AUTH_SOCK:-${TEMP:-/tmp}/.ssh-pageant-$USERNAME}")
fi
unset SSH_PAGEANT

Along with fixes in #23, I believe your issue should be solved, but please re-open this and let me know if it is not.