<?xml version="1.0" encoding="UTF-8"?><rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/"><channel><title>Hoshikawa&apos;s Secret Room</title><description>Kaede Hoshikawa&apos;s Blog</description><link>https://www.futures.moe</link><language>en</language><item><title>How to Connect to WSL via SSH</title><link>https://www.futures.moe/posts/ssh-to-wsl</link><guid isPermaLink="true">https://www.futures.moe/posts/ssh-to-wsl</guid><description>A guide to connecting to WSL via SSH reliably, whilst also supporting mouse event reporting.</description><pubDate>Fri, 28 Aug 2026 00:00:00 GMT</pubDate><content:encoded>&lt;p&gt;Currently, if someone wants to connect to WSL from another machine via SSH, there are mainly two solutions:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Register port forwarding via &lt;code&gt;netsh&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Execute &lt;code&gt;wsl.exe&lt;/code&gt; after establishing an SSH connection to Windows.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;The first solution will not work if you have not logged in to Windows, and it would require a script to keep WSL running.
It also does not track IP changes if the WSL instance reboots. On the other hand, the second solution lacks
mouse reporting, as OpenSSH for Windows does not support mouse event reporting yet.
This means you will not be able to scroll in the terminal, nor use it to move your cursor in programs such as Vim.
In addition, since it is not connected to the WSL instance via SSH, anything that is more than a TTY (e.g. SFTP) does not quite work like a native connection.&lt;/p&gt;
&lt;h3&gt;Prerequisites&lt;/h3&gt;
&lt;p&gt;In a perfect solution, the SSH connection should:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Support mouse event reporting.&lt;/li&gt;
&lt;li&gt;Work with other SSH features such as SFTP and port forwarding.&lt;/li&gt;
&lt;li&gt;Still be reachable after the IP of the WSL instance changes.&lt;/li&gt;
&lt;li&gt;Be able to connect as long as the Windows machine is turned on.&lt;/li&gt;
&lt;/ol&gt;
&lt;h3&gt;Analysis&lt;/h3&gt;
&lt;p&gt;In order to solve requirements 1 and 2, we need to actually connect to the SSH server inside WSL and not just provide a terminal.
Since Windows forwards the WSL port to the same port on the Windows host, we can connect to the SSH server in WSL via Windows,
using it as an SSH jump host, which satisfies requirement 3.
To achieve the last requirement, we need to run a program that keeps the WSL instance open for the duration of the SSH connection.
This can be achieved with Task Scheduler or by running a command via the &lt;code&gt;RemoteCommand&lt;/code&gt; option. However, using a &lt;code&gt;RemoteCommand&lt;/code&gt;
would conflict with the previous jump host approach, as an SSH connection cannot both act as a jump host and execute a remote command.
Using Task Scheduler means you need to wait until the next time the scheduled task is executed for the VM to be booted.&lt;/p&gt;
&lt;h3&gt;The Perfect Solution&lt;/h3&gt;
&lt;p&gt;Before SSH natively provided the jump host feature, jump hosts were usually achieved by specifying a &lt;code&gt;ProxyCommand&lt;/code&gt; in the &lt;code&gt;~/.ssh/config&lt;/code&gt; file,
where the jump host runs netcat (&lt;code&gt;nc&lt;/code&gt;), which opens a TCP connection to the real host and forwards it via stdin and stdout.
If we use &lt;code&gt;wsl.exe&lt;/code&gt; to execute &lt;code&gt;nc&lt;/code&gt; to forward &lt;code&gt;localhost:22&lt;/code&gt;, then we are able to achieve an SSH connection satisfying all the above requirements without any major drawbacks.&lt;/p&gt;
&lt;p&gt;First, we need to install the OpenSSH server inside the WSL instance and enable it to start when the WSL instance starts.&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;$ sudo nala install openssh-server
$ sudo systemctl enable --now ssh
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;We can then configure the SSH server in the WSL instance as usual.
If you are new to setting up OpenSSH on a Linux/UNIX server,
you can refer to &lt;a href=&quot;https://documentation.ubuntu.com/server/how-to/security/openssh-server/index.html&quot;&gt;this Ubuntu guide&lt;/a&gt; on setting up an SSH server on Linux.&lt;/p&gt;
&lt;p&gt;After the SSH server is set up and enabled as a systemd service,
in order for &lt;code&gt;wsl.exe&lt;/code&gt; to forward the traffic as a &lt;code&gt;ProxyCommand&lt;/code&gt;, we also need to install &lt;code&gt;netcat&lt;/code&gt;.&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;$ sudo nala install netcat-openbsd
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;After the SSH server is installed in the WSL instance, we also need to enable the OpenSSH server on Windows.
Unlike Linux/UNIX, authorised keys are managed differently on Windows.
If you are not familiar with setting up OpenSSH on Windows,
you can check out &lt;a href=&quot;https://learn.microsoft.com/en-us/windows-server/administration/OpenSSH/openssh-server-configuration&quot;&gt;this guide&lt;/a&gt;
from Microsoft.&lt;/p&gt;
&lt;p&gt;After the OpenSSH server on the Windows host is set up, we can verify the connection with the following command:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;$ ssh Windows-Desktop ver

Microsoft Windows [Version 10.0.26100.3915]
Connection to windows-desktop.local closed.
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Once we are able to connect to the Windows host via SSH, the last step is to configure the SSH client
so that it connects to the WSL VM using &lt;code&gt;wsl.exe&lt;/code&gt; and &lt;code&gt;nc&lt;/code&gt; as the &lt;code&gt;ProxyCommand&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;On the computer where you will use the SSH client, set the SSH config as follows:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;Host WSL-Ubuntu
HostName does-not-matter.dummy # Since we are using a proxy command, we can use any value.
Port 22 # Same as above, we can use any value.
User futursolo # This should be your username in WSL
IdentityFile ~/.ssh/id_wsl_ubuntu # This should be the SSH key you set for your WSL VM.
ProxyCommand ssh Windows-Desktop C:\\WINDOWS\\System32\\wsl.exe -- nc localhost 22

Host Windows-Desktop
HostName windows-desktop.local # This should be the IP / hostname of your Windows machine.
Port 22 # This should be the port of the OpenSSH Server on Windows.
User futursolo # This should be your username on Windows.
IdentityFile ~/.ssh/id_windows # This should be the SSH key you set for your Windows PC.
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Now we should be able to connect to the WSL machine using the &lt;code&gt;ssh&lt;/code&gt; command.&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;$ ssh WSL-Ubuntu uname -r
5.15.167.4-microsoft-standard-WSL2
Connection to does-not-matter.dummy closed.
&lt;/code&gt;&lt;/pre&gt;
&lt;h3&gt;Enjoy!&lt;/h3&gt;
</content:encoded></item></channel></rss>