Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

copy from stdin to pipe failed #13

Open
bendem opened this issue Jun 3, 2020 · 3 comments
Open

copy from stdin to pipe failed #13

bendem opened this issue Jun 3, 2020 · 3 comments

Comments

@bendem
Copy link

bendem commented Jun 3, 2020

Hi all, I'm trying to follow this article to forward msys2's ssh-agent request to the "native" windows openssh agent using this command:

socat UNIX-LISTEN:/tmp/ssh-agent-pipe EXEC:"npiperelay.exe -ep -v -s //./pipe/openssh-ssh-agent"

and I'm getting this error:

2020/06/03 15:36:00 connecting to //./pipe/openssh-ssh-agent
2020/06/03 15:36:00 connected
2020/06/03 15:36:00 copy from stdin to pipe failed: read /dev/stdin: invalid argument.

which I don't quite understant. I've done quite a bit of research, but I'm no go developer nor windows expert and I'm stuck with this error and no idea how to fix it. I found uber-go/zap#328 which says something about the error being ignorable, but commenting the log.Fatalln call after io.Copy doesn't fix the problem.

Let me know how I can help, <3

@ttk
Copy link

ttk commented Feb 5, 2023

Although the documented steps for wsl work flawlessly, for msys2 it gave me the same error you reported. I found a solution by simply adding the pipes modifier on the EXEC command. i.e.

socat UNIX-LISTEN:/tmp/ssh-agent.sock,fork EXEC:"npiperelay.exe -ep -s //./pipe/openssh-ssh-agent",pipes

as suggested in this post. socat can be installed in mysys2 via pacman -S socat.

I also confirmed that using putty's plink also works (if you don't want to compile npiperelay):

socat UNIX-LISTEN:/tmp/ssh-agent.sock,umask=066,fork EXEC:"PLINK.EXE -serial //./pipe/openssh-ssh-agent",pipes

where you can download plink.exe from putty's download page and place it in your PATH.

@ttk
Copy link

ttk commented Feb 5, 2023

I found that my suggestion above, for msys2, doesn't work when using agent forwarding. Yet it works from WSL. The only difference between the two are the socat binary and the nofork vs pipes modifier. It's so close to working perfectly...

@ttk
Copy link

ttk commented Oct 4, 2024

I was able to successfully forward the Windows SSH agent to msys2 by following this guide with the following changes to .bashrc to accommodate msys2:

export SSH_AUTH_SOCK=${HOME}/.ssh/agent.sock
ssh-add -l >/dev/null 2>&1
if [ $? = 2 ]; then
 rm -f ${SSH_AUTH_SOCK}
 ( setsid socat UNIX-LISTEN:${SSH_AUTH_SOCK},fork EXEC:"npiperelay.exe -ei -s //./pipe/openssh-ssh-agent",pipes & ) >/dev/null 2>&1
 echo "Established connection to Windows SSH agent"
fi

Note: I couldn't find ss command in the msys2 package repo, so I replaced that with a check on the ssh-add -l command. Also I replaced nofork with pipes in the socat command.

The last time I tried this (back in the beginning of 2023), it didn't work. As per the above guide, it's important to upgrade your windows version of OpenSSH and also use the latest version of the forked npiperelay tool.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants