I run emacs in Windows, and do all my development in wsl. Doing it this way means the laptop will go to sleep: running a graphical application in wsl seems to block suspend because it uses RDP.
I’ve got a cool wsl method for tramp,
but it doesn’t let a remote ssh access any agents.
If I’m editing code that lives in wsl,
an I try to git push or git pull,
it prompts for SSH credentials.
The main reason I can find is that tramp really wants to run /bin/sh,
which doesn’t source the .profile or .shrc (or .bashrc if your sh is Bash).
Even if you have an ssh agent running in the wsl container,
the ssh process started by git from emacs won’t know how to talk to it.
Probably the right way to do this would be to get tramp to send an environment variable pointing to the ssh agent running inside the container.
The easier way
The anvil editor comes with a built-in ssh client, and tightly integrated support for editing over ssh connections. The advantage is that any shells you start remotely inherit the SSH auth socket, since SSH has a mechanism to pass that along. wsl doesn’t have anything like that, unfortunately.
The solution I’m using now is to ssh in to my wsl container! It feels like a kludge, but it works just fine, and it solves all the agent issues.
Setting everything up
In wsl, I installed an openssh server, and bound it to port 22
in /etc/ssh/sshd_config.
In Windows, use the OpenSSH that now ships with Windows (Settings → Optional Features, then add OpenSSH Client), and the Windows ssh-agent (Services → OpenSSH Authentication Agent, change startup type to Automatic). Click “Start” while you’re in there to start the agent for the current session.
Make sure a key is installed in Windows
in ~/.ssh/,
then run ssh-add in PowerShell to authenticate.
In ~/.ssh/config,
set up a stanza for your wsl host (I named mine wsl).
The most important thing here is ForwardAgent,
which will pass into wsl a connection to your Windows ssh agent:
Host wsl
Hostname localhost
Port 222
User neale
ForwardAgent yes
… and then everything worked for me! tramp worked in eshell, vc-mode was able to push and pull, and things seem happy!