Giter VIP home page Giter VIP logo

wsl-ssh-agent's Introduction

  wsl-ssh-agent

IMPORTANT NOTE ON PROJECT HISTORY

This project was started at the time when WSL2 did not exist and Microsoft just implemented AF_UNIX socket support. Today it is useful only when WSL1 is being required - which is really rare. Sharing Windows side ssh-agent with WSL2 does not need wsl-ssh-agent.exe at all! Please, read on next section on how to setup WSL2 and only continue after that if you really working with WSL1.

WSL2 compatibility

At the moment AF_UNIX interop does not seem to be working with WSL2 VMs. Hopefully this will be sorted out eventually. Meantime there is an easy workaround (proposed by multiple people) which does not use wsl-ssh-agent.exe and relies on combination of linux socat tool from your distribution and npiperelay.exe. For example put npiperelay.exe on drvfs for interop to work its magic (I have winhome ⇒ /mnt/c/Users/rupor, copy wsl-ssh-agent-relay into your ~/.local/bin directory, and add following 2 lines to your .bashrc/.zshrc file:

${HOME}/.local/bin/wsl-ssh-agent-relay start
export SSH_AUTH_SOCK=${HOME}/.ssh/wsl-ssh-agent.sock

You really have to be on WSL 2 in order for this to work - if you see errors like Cannot open netlink socket: Protocol not supported - you probably are under WSL 1 and should not use this workaround. Run wsl.exe -l --all -v to check what is going on. When on WSL 2 make sure that npiperelay.exe is on windows partition and path is right. For convenience I will be packing pre-build npiperelay.exe with wsl-ssh-agent. Please also ensure that socat is installed: sudo apt install socat.

NOTE: You may be running Linux distribution with OpenSSH version more recent than your Windows host has out of the box. Presently Ubuntu 22.04 and Arch both demonstrate this - communication with ssh-agent will fail. In such cases please visit Windows OpenSSH development and update your Windows OpenSSH with latest release.

NOTE: If you are having issues using wsl-ssh-agent-relay with systemd try adding :WSLInterop:M::MZ::/init:PF to /usr/lib/binfmt.d/WSLInterop.conf. For example (thanks to rkl110 - Microsoft/WSL - Issue 8843):

sudo sh -c 'echo :WSLInterop:M::MZ::/init:PF > /usr/lib/binfmt.d/WSLInterop.conf'

Helper to interface with Windows ssh-agent.exe service from WSL1 (replacement for ssh-agent-wsl).

GitHub Release

Windows has very convenient ssh-agent service (with support for persistence and Windows security). Unfortunately it is not accessible from WSL. This project aims to correct this situation by enabling access to SSH keys held by Windows own ssh-agent service from inside the Windows Subsystem for Linux.

My first attempt - ssh-agent-wsl was successful, but due to Windows interop restrictions it required elaborate life-time management on the WSL side. Starting with build 17063 (which was many updates ago) Windows implemented AF_UNIX sockets. This makes it possible to remove all trickery from WSL side greatly simplifying everything.

NOTE: If you need access to more functionality (smard cards, identity management) provided by GnuPG set of tools on Windows or if you are looking for compatibility with wider set of utilities, like Git for Windows, Putty, Cygwin - you may want to take a look at win-gpg-agent instead.

wsl-ssh-agent-gui.exe is a simple "notification tray" applet which maintains AF_UNIX ssh-agent compatible socket on Windows end. It proxies all requests from this socket to ssh-agent.exe via named pipe. The only thing required on WSL end for it to work is to make sure that WSL SSH_AGENT_SOCK points to proper socket path. The same socket could be shared by any/all WSL sessions.

As an additional bonus wsl-ssh-agent-gui.exe could work as remote clipboard server so you could send your clipboard from tmux or neovim remote session back to your windows box over SSH secured connection easily.

NOTE: BREAKING CHANGE Version 1.5.0 introduces breaking change. If you were not using wsl-ssh-agent-gui.exe as lemonade clipboard backend - this should not concern you at the slightest. Otherwise lemonade support no longer - it has been replaced with gclpr which is more secure.

NOTE: BREAKING CHANGE Version 1.6.0 introduces breaking change. If you were not using wsl-ssh-agent-gui.exe as gclpr clipboard backend - this should not concern you at the slightest. Otherwise starting with v1.1.0 gclpr server backend (included with v1.6.0) enforces protocol visioning and may require upgrade of gclpr tools.

SECURITY NOTICE: All the usual security caveats applicable to WSL apply. Most importantly, all interaction with the Win32 world happens with the credentials of the user who started the WSL environment. In practice, if you allow someone else to log in to your WSL environment remotely, they may be able to access the SSH keys stored in your ssh-agent. This is a fundamental feature of WSL; if you are not sure of what you're doing, do not allow remote access to your WSL environment (i.e. by starting an SSH server).

COMPATIBILITY NOTICE: wsl-ssh-agent-gui was tested on Windows 10 1903 with multiple distributions and should work on anything starting with 1809 - beginning with insider build 17063 and would not work on older versions of Windows 10, because it requires AF_UNIX socket support feature.

Installation

    scoop install https://github.com/rupor-github/wsl-ssh-agent/releases/latest/download/wsl-ssh-agent.json

and updating:

    scoop update wsl-ssh-agent

Alternatively download from the releases page and unpack it in a convenient location.

Starting with v1.5.1 releases are packed with zip and signed with minisign. Here is public key for verification:

  RWTNh1aN8DrXq26YRmWO3bPBx4m8jBATGXt4Z96DF4OVSzdCBmoAU+Vq

Usage

  1. Ensure that on Windows side ssh-agent.exe service (OpenSSH Authentication Agent) is started and has your keys. (After adding keys to Windows ssh-agent.exe you may remove them from your wsl home .ssh directory - just do not forget to adjust IdentitiesOnly directive in your ssh config accordingly. Keys are securely persisted in Windows registry, available for your account only). You may also want to switch its startup mode to "automatic". Using powershell with elevated privileges (admin mode):
	Start-Service ssh-agent
	Set-Service -StartupType Automatic ssh-agent
  1. Run wsl-ssh-agent-gui.exe with arguments which make sense for your usage. Basically there are several ways:

    • Using -socket option specify "well known" path on Windows side and then properly specify the same path in every WSL session:

      Windows: cmd wsl-ssh-agent-gui.exe -socket c:\wsl-ssh-agent\ssh-agent.sock

      WSL: bash export SSH_AUTH_SOCK=/mnt/c/wsl-ssh-agent/ssh-agent.sock

    • You could avoid any actions on WSL side by manually setting SSH_AUTH_SOCK and WSLENV=SSH_AUTH_SOCK/up on Windows side (see note below).

    • Using -setenv option allows application automatically modify user environment, so every WSL session started while wsl-ssh-agent-gui.exe is running will have proper SSH_AUTH_SOCK available to it (using WSLENV). By default socket path points to user temporary directory. Usual Windows user environment modification rules are applicable here (see note below).

NOTE: Setting SSH_AUTH_SOCK environment on Windows side may (and probably will) interfere with some of Windows OpenSSH. As far as I could see presently utilities in Windows\System32\OpenSSH expect this environment variable to be either empty or set to proper ssh-agent.exe pipe, otherwise they cannot read socket:

	if (getenv("SSH_AUTH_SOCK") == NULL)
		_putenv("SSH_AUTH_SOCK=\\\\.\\pipe\\openssh-ssh-agent");

To avoid this and still be able to use -setenv and automatically generated socket path use -envname to specify variable name to set. Later on WSL side you could use:

export SSH_AUTH_SOCK=${<<YOUR-NAME-HERE>>}

When wsl-ssh-agent-gui.exe is running you could see what it is connected to by clicking on its icon in notification tray area and selecting About. At the bottom of the message you would see something like:

Socket path:
  C:\Users\rupor\AppData\Local\Temp\ssh-273683143.sock
Pipe name:
  \\.\pipe\openssh-ssh-agent
Remote clipboard:
  gclpr is serving 2 key(s) on port 2850

For security reasons unless -nolock argument is specified program will refuse access to ssh-agent.exe pipe when user session is locked, so any long running background jobs in WSL which require ssh may fail.

Options

Run wsl-ssh-agent-gui.exe -help

---------------------------
wsl-ssh-agent-gui
---------------------------

Helper to interface with Windows ssh-agent.exe service from WSL

Version:
	1.5.0 (go1.15.6)

Usage:
	wsl-ssh-agent-gui [options]

Options:

  -debug
    	Enable verbose debug logging
  -envname name
    	Environment variable name to hold socket path (default "SSH_AUTH_SOCK")
  -help
    	Show help
  -line-endings string
    	Remote clipboard convert line endings (LF/CRLF)
  -nolock
    	Provide access to ss-agent.exe even when user session is locked
  -pipe name
    	Pipe name used by Windows ssh-agent.exe
  -port int
    	Remote clipboard port (default 2850)
  -setenv
    	Export environment variable with 'envname' and modify WSLENV
  -socket path
    	Auth socket path (max 108 characters)

Example

Putting it all together nicely - remote here refers to your wsl shell or some other box or virtual machine you could ssh to.

For my WSL installations I always create ~/winhome and link it to my Windows home directory (where I have .wsl directory with various interoperability tools from Windows side). I am assuming that gclpr is in your path on remote and you installed it's Windows counterpart somewhere in drvfs location (~/winhome/.wsl is a good place).

I auto-start wsl-ssh-agent-gui.exe on logon on my Windows box using following command line:

wsl-ssh-agent-gui.exe -setenv -envname=WSL_AUTH_SOCK

In my .bashrc I have:

[ -n ${WSL_AUTH_SOCK} ] && export SSH_AUTH_SOCK=${WSL_AUTH_SOCK}

and my .ssh/config entries used to ssh to remote have port forwarding enabled:

RemoteForward 2850 127.0.0.1:2850

On remote my tmux.conf includes following lines:

set -g set-clipboard off
if-shell 'if [ -n ${WSL_DISTRO_NAME} ]; then true; else false; fi' \
  'bind-key -T copy-mode-vi Enter send-keys -X copy-pipe-and-cancel "~/winhome/.wsl/gclpr.exe copy" ; bind-key -T copy-mode-vi MouseDragEnd1Pane send-keys -X copy-pipe-and-cancel "~/winhome/.wsl/gclpr.exe copy"' \
  'bind-key -T copy-mode-vi Enter send-keys -X copy-pipe-and-cancel "gclpr copy" ; bind-key -T copy-mode-vi MouseDragEnd1Pane send-keys -X copy-pipe-and-cancel "gclpr copy"'

And my neovim configuration file init.vim on remote has following lines:

set clipboard+=unnamedplus
if has("unix")
	" ----- on UNIX ask lemonade to translate line-endings
	if empty($WSL_DISTRO_NAME)
		if executable('gclpr')
			let g:clipboard = {
				\   'name': 'gclpr',
				\   'copy': {
				\      '+': 'gclpr copy',
				\      '*': 'gclpr copy',
				\    },
				\   'paste': {
				\      '+': 'gclpr paste --line-ending lf',
				\      '*': 'gclpr paste --line-ending lf',
				\   },
				\   'cache_enabled': 0,
				\ }
		endif
	else
		" ---- we are inside WSL - reach out to the Windows side
		if executable($HOME . '/winhome/.wsl/gclpr.exe')
			let g:clipboard = {
				\   'name': 'gclpr',
				\   'copy': {
				\      '+': $HOME . '/winhome/.wsl/gclpr.exe copy',
				\      '*': $HOME . '/winhome/.wsl/gclpr.exe copy',
				\    },
				\   'paste': {
				\      '+': $HOME . '/winhome/.wsl/gclpr.exe paste --line-ending lf',
				\      '*': $HOME . '/winhome/.wsl/gclpr.exe paste --line-ending lf',
				\   },
				\   'cache_enabled': 0,
				\ }
		endif
	endif
endif

Now you could open your WSL in terminal of your choice - mintty, cmd, Windows terminal, ssh to your remote using keys stored in Windows ssh-agent.exe without entering any additional passwords and have your clipboard content back on Windows transparently.

Credit


Licensed under the GNU GPL version 3 or later, http://gnu.org/licenses/gpl.html

This is free software: you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law.

wsl-ssh-agent's People

Contributors

benburrill avatar koppor avatar lusitania avatar mishak87 avatar rupor-github avatar tonyke-bot avatar vbrozik avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

wsl-ssh-agent's Issues

Does this work with putty?

Hi,

I want to use putty as ssh client and windows openssh agent as key agent instead of pageant
from putty, but I found it does not work at all.

After I use windows 10 (1909) ssh-add loading my private key , putty still ask for a password,
seems it doesn't find windows key agent service.

Would this wsl-ssh-agent help ?
thanks.

Is this possible with a VM and a samba share?

Pretty much in the heading.

I was about to attempt it but figured I would ask here first. Can this technique be used to share the windows host agent with a Debian 11 vm running on VMWare.

Thanks!

Problems with socat/npiperelay when used on WSL1

I'm on W10 19041.207 and using your .bashrc trick for WSL2 gives me:

Cannot open netlink socket: Protocol not supported

There are nine of these lines, and obviously there's no socat to npiperelay.exe link. Any ideas on how I can get around this?

Chocolatey package possible?

Hey mates!

I've seen there is already an unofficial package for NuGet. Is it possible to also get it for Chocolatey?

I've seen there was someone who tried, but it seems it's not released: #7

WSL2 npiperelay.exe path length limit

followed the directions for WSL2 and it keeps saying error communicating with agent. the only difference was that my location of the exe was in %localappdata%\Programs\wsl-ssh-agent. moved it to %userprofile%\.wsl and it works fine after restarting WSL2. the path is fully expanded in the .bashrc file i.e. /mnt/c/Users/$USER/AppData/Local/Programs/wsl-ssh-agent vs /mnt/c/Users/$USER/.wsl

Why "gpg" in file name?

@rupor-github: In the latest release (v1.5.1) the file name (when ignoring the file extension and format) is now wsl-gpg-agent instead of wsl-ssh-agent. Does this new filename indicate newly added GPG support? Or is this a typo?

Issues using WSL2 with Ubuntu 22.04

Hi,

I am using WSL1 with wsl-ssh-agent-gui which works just fine.
Now I am trying to use WSL2 but it doesn't work (so I have both instances WSL1 and WSL2 and Ubuntu 22.04)
Using it for authentication to git (BitBucket)
WSL2 is configured to use the workaround with the content in ~/.bashrc

export SSH_AUTH_SOCK=$HOME/.ssh/agent.sock
ss -a | grep -q $SSH_AUTH_SOCK
if [ $? -ne 0   ]; then
    rm -f $SSH_AUTH_SOCK
    ( setsid socat UNIX-LISTEN:$SSH_AUTH_SOCK,fork EXEC:"/mnt/c/opt/wsl-ssh-agent/npiperelay.exe -ei -s //./pipe/openssh-ssh-agent",nofork & ) >/dev/null 2>&1
fi

Socat seems to start just fine.

In both WSL1 and WSL2 I get:

> ssh-add -l
3072 SHA256:utd25qwhXccvIb17tC8rncoQj********************* [email protected] (RSA)

But in WSL2 I get:

> git clone ssh://[email protected]/ja/repo.git
Cloning into 'repo'...
[email protected]: Permission denied (publickey).
fatal: Could not read from remote repository.

Any idea what can be wrong?

It is compatible with gpg-connect-agent?

I run source ~/.bashrc containing:

SSHDIR="${HOME}/.ssh"
WINWSLDIR="/mnt/c/WSL"
NPIPERELAY="${WINWSLDIR}/bin/npiperelay.exe"

SSH_AUTH_SOCK="${SSHDIR}/ssh-agent.sock"

ss -a | grep -q $SSH_AUTH_SOCK
if [ $? -ne 0 ]; then
    rm -f $SSH_AUTH_SOCK
    ( setsid socat UNIX-LISTEN:$SSH_AUTH_SOCK,fork EXEC:"${NPIPERELAY} -ei -s //./pipe/openssh-ssh-agent",nofork & )
fi

then ssh-add -l:

2020/05/28 20:15:21 open //./pipe/openssh-ssh-agent: The system cannot find the file specified.
error fetching identities: communication with agent failed

How to use correct key when I have multiple for github.com

I use work key and a personal key on github and have my .ssh\config setup on the Windows side as described at https://gist.github.com/oanhnn/80a89405ab9023894df7. I'm sharing keys with WSL2 with the https://github.com/rupor-github/wsl-ssh-agent#wsl-2-compatibility technique.

Things work well on Windows:

> ssh -T [email protected]
Hi jibbers42! You've successfully authenticated, but GitHub does not provide shell access.

> ssh -T [email protected]
Hi work! You've successfully authenticated, but GitHub does not provide shell access.

But on WSL2 it seems to select my work key for personal (github.com) and the work host (github.com-work) doesn't work at all:

$ ssh -T [email protected]
Hi work! You've successfully authenticated, but GitHub does not provide shell access.

$ ssh -T [email protected]
ssh: Could not resolve hostname github.com-work: Name or service not known

My Windows .ssh\config is pretty simple:

> cat .\.ssh\config
Host github.com
   HostName github.com
   IdentityFile ~/.ssh/jibbers42-ed25519
   IdentitiesOnly yes

Host github.com-work
   HostName github.com
   IdentityFile ~/.ssh/work-ed25519
   IdentitiesOnly yes

Any idea how I can get the WSL2 side to select the correct key?

'Error connecting to agent' on one PC but working correctly on another with identical setup

I have two PCs, both running Windows 10, both with Ubuntu 20.04 installed in WSL 1. Both PCs start their OpenSSH Authentication service automatically on startup. Additionally on startup both run this program with the command:

"C:\Program Files\WSL SSH Agent\wsl-ssh-agent-gui.exe" -setenv -envname WSL_AUTH_SOCK

Both of them also have the following two environment variables (I'm assuming automatically set by this program), identical, just with a different number in the temporary file name:
image

In WSL I have the following line in .bashrc on both PCs:

export SSH_AUTH_SOCK=$WSL_AUTH_SOCK

and nothing else agent-related in either .bashrc or .profile.

However, upon running Ubuntu, on one PC I can use the Windows SSH agent, and on the other I can't. Any idea what else I could try to get it working on the second PC?

PC 1 (Working)

Powershell (outside WSL):

PS C:\Users\User> ssh-add -L
ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIGdmx21Jrea+X7XlvqNc49d+M59SXi/Elia0Sm9yJ4F9 User-PC

WSL:

user@User-PC:~/repo$ echo $WSL_AUTH_SOCK
/mnt/c/Users/User/AppData/Local/Temp/ssh-055412939.sock
user@User-PC:~/repo$ ssh-add -L
ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIGdmx21Jrea+X7XlvqNc49d+M59SXi/Elia0Sm9yJ4F9 User-PC
user@User-PC~/repo$ git pull
Already up to date.

PC 2 (Not working)

Powershell (outside WSL):

PS C:\Users\user> ssh-add -L
ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIP69b6DhaQqgKVZWNnhbSbhBXG1OH3yePiAHfdyTU+f1 user@PC

WSL:

user@PC:~/repo$ echo $WSL_AUTH_SOCK
/mnt/c/Users/user/AppData/Local/Temp/ssh-921384019.sock
user@PC:~/repo$ ssh-add -L
Error connecting to agent: No such file or directory
user@PC:~/repo$ git pull
[email protected]: Permission denied (publickey).
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

SSH_AUTH_SOCK causes ssh-agent stop working on Windows side

Hi,

I'm using wsl-ssh-agent since hours after its first release, great stuff!

At first, I've tried the "-setenv" option and I thought it's very nice, I hadn't have to do anything on WSL side, it's just worked.
Not long after that I've realized that as long as SSH_AUTH_SOCK is set, I cannot use the agent on Windows side.

Windows 10 Pro (18362.356)
OpenSSH_for_Windows_7.7p1, LibreSSL 2.6.5
wsl-ssh-agent 1.2.1

D:\ssh-add -l
error fetching identities: invalid format

D:\ssh -vvv somewhere
...
debug3: failed to open file:D:/dev/tty error:3
debug1: read_passphrase: can't open /dev/tty: No such file or directory
Enter passphrase for key 'C:\Users\someuser/.ssh/id_something_ed25519':

After unsetting the environment variable at least in current session, it's working as usual.

As a workaround I'm specifying explicitly the path to the socket using "-socket" option, and manually exporting the SSH_AUTH_SOCK variable on WSL side with the corresponding path.

Anyway, it's not really a big issue, I'm just curious: is it happening only on my systems or it's a known limitation (not wsl-ssh-agent's, moreso OpenSSH's in Windows)?

SSH agent forwarding to WSL2

Hello @rupor-github ,

I am partially able to use the OpenSSH key (created in Windows) inside my WSL2 (Ubuntu 22.04). I have below setup:

  1. Using Windows 11 (OS build 22621.1702) with OpenSSH enabled and running without any issues and WSL2 with Ubuntu 22.04
  2. In WSL2 copied the wsl-ssh-agent-relay file to ${HOME}/.local/bin/ and added below lines to ~/.bashrc as mentioned in the README
${HOME}/.local/bin/wsl-ssh-agent-relay start
export SSH_AUTH_SOCK=${HOME}/.ssh/wsl-ssh-agent.sock
  1. Also copied npiperelay.exe from wsl-ssh-agent.zip to /mnt/c/Users/<USER>
  2. Shutdown WSL2 and restarted it. And tried to clone to Git repo (key is already added to Git). But this didn't work. I don't have wsl-ssh-agent.sock file in ${HOME}/.ssh/ but only agent.sock.
  3. ssh-add -L didn't return any keys and complained Error connecting to agent: No such file or directory. I don't know why above solution didn't work for me (please let me know if I have missed any steps)

I came across issue Error connecting to agent: No such file or directory and edited ~/.bashrc to include

export SSH_AUTH_SOCK=$HOME/.ssh/agent.sock
ss -a | grep -q $SSH_AUTH_SOCK
if [ $? -ne 0   ]; then
    rm -f $SSH_AUTH_SOCK
    ( setsid socat UNIX-LISTEN:$SSH_AUTH_SOCK,fork EXEC:"/mnt/c/test/npiperelay.exe -ei -s //./pipe/openssh-ssh-agent",nofork & ) >/dev/null 2>&1
fi

And restarted the WSL2. Now, the keys are loaded by ssh-add - L. I have similar results in WSL2 and Powershell. Also, cloning from Git works fine.
But when I try to ssh to a server (key is added to ~/.ssh/authorized_keys) I get error ssh: Could not resolve hostname example.com: Name or service not known
This works fine from Powershell.
I checked the DNS in WSL2 and it seems fine. nslookup could return the IP address.

Could you please let me know what could be the issue and how can I resolve it?

P.S: Please let me know if any info is missing here

Thanks in advance

Connection refused when connecting through IntelliJ IDEA terminal set as WSL

I have setup wsl-ssh-agent-gui to be started with the -setenv option and in WSL I ensure the SSH_AUTH_SOCK env var is set.

When I try to list my SSH identities on a WSL terminal provided by IntelliJ IDEA (by using the terminal startup command wsl -d Ubuntu I get Error connecting to agent: Connection refused.

When I try the same in a Ubuntu shell (or by manually starting the Ubuntu shell by using wsl -d Ubuntu in cmd) I get my identities listed as expected.

Is there some checking going on about where these connections to the agent are coming from which might prevent connections not originating from the "original WSL shell"?

wsl-ssh-agent-gui.exe complains of lack of ~/.gclpr directory even if gclpr is not being used

Going from wsl-ssh-agent 1.5.2 to 1.6.0, suddenly the presence of gclpr seems to be enforced. With 1.5.2, I can just start it up with my environment and there's no problem. With 1.6.0, I get this error:

image

If I create an empty .gclpr directory, both 1.5.2 and 1.6.0 report the same error (bad permissions on a nonexistent file in that directory), so this appears to be a regression.

`-setenv` by default

Please enable this option by default. Currently the variable SSH_AUTH_SOCK (or its override) is not present within the WSL environment without setting the option. From what I understand however this is the intended purpose of wsl-ssh-agent-gui.exe. IMO having an option -nosetenv is more reasonable, if needed at all.

Pass name of process?

Would it be possible to pass the name of the process requesting the keys?
Currently npiperelay is shown in the tray by KeeAgent plugin/KeePass.
It would be nice if the underlying process is shown, e.g. ssh or sftp.

WSL2 won't get keys despite agent has em

Thank you very much for this awesome Project but I'm afraid I need to ask for help:
After fideling with this for some hours, where I wasted the first few as I thought I could simply transfer from WSL1... :-(

When I try to connect to a host like that: "ssh -i .ssh/mykey myhost -vvv" I see this:

debug3: ssh_get_authentication_socket_path: path '/home/mircsicz/.ssh/wsl-ssh-agent.sock'
debug2: get_agent_identities: ssh_agent_bind_hostkey: communication with agent failed
debug1: get_agent_identities: ssh_fetch_identitylist: communication with agent failed

and it asks for the passwd to the key but it's there:

ssh-add -l
4096 SHA256:string mykey (RSA)

I've wsl-ssh-agent-relay in place (~/bin/wsl-ssh-agent-relay) also changed "RELAY_BIN="${HOME}/bin/npiperelay.exe" and an entry in my .bashrc:

${HOME}/bin/wsl-ssh-agent-relay start
export SSH_AUTH_SOCK=${HOME}/.ssh/wsl-ssh-agent.sock

And yes it's def WSL2:

C:\Users\mircsicz>wsl.exe -l --all -v
  NAME          STATE           VERSION
- kali-linux    Running         2

But now I'm totally out of ideas!

Gracefully stop wsl-ssh-agent-gui from command line

I'm creating a chocolatey package for wsl-ssh-agent (package source). I want to gracefully stop wsl-ssh-agent-gui process before updating wsl-ssh-agent package.

When I forcibly stop wsl-ssh-agent-gui by powershell Stop-Process cmdlet, socket file and lock file generated by wsl-ssh-agent-gui (like ssh-126447479.sock, wsl-ssh-agent-gui.lock) remain in %TEMP% folder.

Is there a good method to gracefully stop wsl-ssh-agent-gui process from command line (powershell or cmd)?

WSL2 and Windows 11 ssh not working

Hello,
I'm running debian 11 in WSL2 on Windows 11 host,
Every time when i'm trying to use ssh with wsl-ssh-agent i'm getting an error like:
debug1: get_agent_identities: ssh_get_authentication_socket: No such file or directory

This occurs only for ssh commands, ssh-add -L (and -l) works well - it returns all keys available in the agent.
I've already double checked SSH versions:
Debian:

OpenSSH_8.9p1, OpenSSL 1.1.1n  15 Mar 2022

Windows:

OpenSSH_for_Windows_8.9p1, LibreSSL 3.4.3

How to troubleshoot this?

Thank you

Following Instruction for npiperelay results in invalid ELF header

I am trying to get pageant working with WSL2 on windows 10 build 1903 - I'm mainly stuck on the part where the SSH agent opens the DLL for pageant to prompt for authentication, my pageant certificate is a dll, and when WSL2 tries to open that, it fails with this message:

dlopen /mnt/c/Program Files/Package/acpkcs211.dll failed: /mnt/c/Program Files/Package/acpkcs211.dll: invalid ELF header

I'm unsure where this is failing, at the Npiperelay, or the ssh agent, so I thought I'd start here. Thanks for the help, and I hope this gets other people to a closer solution.

Environment variable not being set

Running version 1.4 on 64-bit Windows 10 Pro Version 1909 OS Build 18363.535 and WSL version 1. The environment variable is not exported to WSL. I have tried using -setenv on its own and in combination with -envname to set a variable name. I have also tried both combinations with and without specifically specifying a socket path using -socket.

Connection might not work after update to Ubuntu 22.04

Dear all,

I recently had to update my Ubuntu to 22.04 due to various reasons. Unfortunately, this broke the ssh-agent interoperability.

After a lot of research, it turned out, that there was a recent change in the agent communication, leading to errors like:

debug1: get_agent_identities: ssh_fetch_identitylist: communication with agent failed

The solution for me was to update my OpenSSH instance. This required disabling the built-in OpenSSH, and install the most recent version from https://github.com/PowerShell/Win32-OpenSSH/releases . After adding this OpenSSH version to the Windows PATH (e.g. by adding %ProgramFiles%\OpenSSH\ ), everything works again as before.

Please note, that I am using WSL2 and npiperelay . But I assume that this will affect wsl-ssh-agent as well.

Best,

Andreas

WSL 2 setup

Hello there, that's not a real issue but a question. I'm really helpless so I need to ask for your help.
Today I decided to update my windows to version 2004 and use WSL 2 to see if the issues I had with the first version are gone.

What were the steps I have did?

  1. Enable OpenSSH in Windows Services
  2. Download WSL 2 Workaround files
  3. Extract downloaded files (C:\Users\$USER\.wsl)
  4. Open KeepassXC (v. 2.6.0)
  5. Settings → SSH Agent
  6. Check following options
    7. Enable SSH Agent integration
    8. Use OpenSSH for Windows instead of pageant
  7. Make a simple test in PowerShell (ssh -T [email protected]) (it works)
  8. Open WSL and add following to .bashrc
export SSH_AUTH_SOCK=$HOME/.ssh/ssh-agent.sock
ss -a | grep -q $SSH_AUTH_SOCK
if [ $? -ne 0   ]; then
            rm -f $SSH_AUTH_SOCK
                ( setsid socat UNIX-LISTEN:$SSH_AUTH_SOCK,fork EXEC:"/mnt/c/Users/$USER/.wsl/npiperelay.exe -ei -s //./pipe/openssh-ssh-agent",nofork & ) >/dev/null 2>&1
fi
  1. Before restarting wsl I have ran following command in PowerShell:
    .\wsl-ssh-agent-gui.exe -socket C:\Users\$USER\.wsl\ssh-agent.soc
  2. Check if the paths are correct
C:\Users\$USER\.wsl\ssh-agent.sock

\\.pipe\openssh-ssh-agent

I thought that the SSH_AUTH_SOCK path may be wrong but even chaning it to the same path as in gui it still does not work. The ssh-agent.sock is being deleted because of the rm -f $SSH_AUTH_SOCK which should be clear.

I really do not know what I am doing wrong, could someone help me and tell me what I am doing wrong?
Thanks in advance.

Release archive using ZIP instead of 7zip

Hello,

since the release is mainly a Windows application and 7-ZIP is not natively supported on Windows it would be great to offer ZIP download (like the source code release) which is natively supported on Windows.
Otherwise, you first have to download and install external software only to use your software.

Hide systray icon

Hey,
Thanks for this great tool!
Is there a way to hide the tray icon? I'd like to have it running in the background at startup without cluttering the taskbar.
Thanks in advance for your answer.

[Question] `npiperelay.exe` build

The releases of this project come with the npiperelay.exe binary already included, which is very helpful.
Should this be the same npiperelay.exe as from the upstream npiperelay repository,
or were adjustments necessary to make it work more smoothly?

Delay in minutes before systray icon appears after startup of the agent - and vice-versa

After starting wsl-ssh-agent.exe there is a long delay (in minutes) before systray icon appears.
That also means that the socket is not working until the icon appears. The background agent process itself starts right away.

I am testing whether it works or not simply by executing the below command:

ssh-add - < /mnt/c/Users/Romas/.ssh/id_rsa

And until the systray icon appears I am getting error of

Error connecting to agent: No such file or directory

Once agent systray icon appears, WSL's ssh-add command works as expected and asks for key password input.

Also, exiting via windows systray icon menu keeps wsl-ssh-agent-gui.exe process running for minutes.

I am on Windows 10 Pro v1909, WSL starting the tool with the below args:
wsl-ssh-agent-gui.exe -setenv -envname=WSL_AUTH_SOCK -socket e:\ssh-agent.sock

"communication with agent failed" when trying to connect using SSH in Arch (WSL 2)

Hi! Not sure if I should report this issue here, but I figured you might be able to help me further at least.

For some reason wsl-ssh-agent doesn't seem to work (or well, only partially works) under Arch (either installed through https://github.com/nullpo-head/wsl-distrod or https://github.com/yuk7/ArchWSL). If I run ssh-add -l it connects to the ssh-agent just fine and lists my keys, but when I actually try to SSH somewhere it still asks me for my passphrase and I see this in the verbose log:

debug2: get_agent_identities: ssh_agent_bind_hostkey: communication with agent failed
debug1: get_agent_identities: ssh_fetch_identitylist: communication with agent failed

It "just works" in Ubuntu WSL environments (both through Microsoft Store and through https://github.com/nullpo-head/wsl-distrod), but the exact same setup does not seem to work under Arch.

Let me know if you need any more info from me, I'm not sure what exactly I should supply. And apologies if this setup is unsupported, feel free to close the issue if that's the case. I just figured since this doesn't seem to be Distrod or ArchWSL specific but rather distro-specific I might as well start by asking here.

Crash during system booting

I add this program as a autorun item into my windows. I found that wsl-ssh-agent sometimes crashes during autorun.

What may possibly lead to this crash?
Launch command: "C:\Data\Program\wsl-ssh-agent-gui.exe" -setenv -envname=WSL_AUTH_SOCK

Lockfile cannot be created

Hello,

I got the problem that the application wont start for me, except I run it in admin mode. But this is problematic, because then I cannot put it into autostart. I did a bit of debugging and this is the debugview output:

[16160] [wsl-ssh-agent-gui] Windows - CurrentMajorVersionNumber: 10, CurrentBuild: 18363
[16160] [wsl-ssh-agent-gui] Application already running

But the lock-file wasnt there. I then took ProcMon to view File accesses and you can see:

21:16:31,1798246	wsl-ssh-agent.exe	8816	CreateFile	C:\Users\MYUSERNAME\AppData\Local\Temp\wsl-ssh-agent-gui.lock	NAME NOT FOUND	Desired Access: Read Attributes, Disposition: Open, Options: Open Reparse Point, Attributes: n/a, ShareMode: Read, Write, Delete, AllocationSize: n/a
21:16:31,1800598	wsl-ssh-agent.exe	8816	CreateFile	C:\Users\MYUSERNAME\AppData\Local\Temp\wsl-ssh-agent-gui.lock	NAME NOT FOUND	Desired Access: Read Attributes, Synchronize, Disposition: Open, Options: Synchronous IO Non-Alert, Attributes: n/a, ShareMode: None, AllocationSize: n/a
21:16:31,1803939	wsl-ssh-agent.exe	8816	CreateFile	C:\Users\MYUSERNAME\AppData\Local\Temp\wsl-ssh-agent-gui.lock	ACCESS DENIED	Desired Access: Generic Write, Read Attributes, Disposition: Create, Options: Synchronous IO Non-Alert, Non-Directory File, Attributes: N, ShareMode: Read, Write, AllocationSize: 0
21:16:31,1807090	wsl-ssh-agent.exe	8816	CreateFile	C:\Users\MYUSERNAME\AppData\Local\Temp\wsl-ssh-agent-gui.lock	NAME NOT FOUND	Desired Access: Read Data/List Directory, Synchronize, Disposition: Open, Options: Directory, Synchronous IO Non-Alert, Attributes: n/a, ShareMode: Read, Write, Delete, AllocationSize: n/a

As you can see in Line 3 (Lines 1,2 and 4 are just checks from your application, if the file is already there), it gets AccessDenied on creation of the lockfile. But the permissions are all correct:

PS C:\Users\MYUSERNAME\AppData\Local\Temp> Get-Acl | Format-List


Path   : Microsoft.PowerShell.Core\FileSystem::C:\Users\MYUSERNAME\AppData\Local\Temp
Owner  : MYPC\MYUSERNAME
Group  : NT-AUTORITÄT\SYSTEM
Access : NT-AUTORITÄT\SYSTEM Allow  FullControl
         VORDEFINIERT\Administratoren Allow  FullControl
         MYPC\MYUSERNAME Allow  FullControl
Audit  :
Sddl   : O:S-1-5-21-1011926168-4098507291-4013957409-1000G:SYD:(A;OICIID;FA;;;SY)(A;OICIID;FA;;;BA)(A;OICIID;FA;;;S-1-5
         -21-1011926168-4098507291-4013957409-1000)

The process also runs under the correct user MYUSERNAME.

Sadly I have no idea how to debug this further... Any suggestions?

Harder to setup

As part of the description for this project, it says it aims to be "much easier to use" than the original ssh-agent-wsl. However I found the instructions in ssh-agent-wsl much more simple to follow: there was a 1, 2, 3 process for setting up which didn't require any choices from the user, and it worked perfectly for me.

In wsl-ssh-agent, there are several options to choose from in step 2 of "Usage", and it was very unclear to me which one I should be choosing. After reading them several times I took a stab at the first option, and eventually it worked. It would be really helpful to call this the 'standard' or 'default' option, for people like me who don't have a clue which one to choose.

Feature request: disable clipboard server?

Could we have a way to disable the clipboard functionality? From quick code inspection it seems to do nothing unless ~/.gclpr exists, but I'd be more comfortable (from a security paranoia standpoint) knowing that it was explicitly disabled.

npiperelay.exe doesn't work for WSL 2 starting from Windows 11 22000.318

I was able to use npiperelay to forward ssh agent request until 22000.318. After upgrading, I got error fetching identities: communication with agent failed in the WSL 2.

Didn't get a chance to debug this issue yet but open an issue first to see if anyone else is encountering the same issue. Will try to debug when I get some time.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.