{"id":5111,"date":"2026-08-30T06:50:33","date_gmt":"2026-08-29T21:50:33","guid":{"rendered":"https:\/\/donguri3.net\/server-tech\/wsl2-x11-forwarding-linux-2\/"},"modified":"2026-08-30T06:50:34","modified_gmt":"2026-08-29T21:50:34","slug":"wsl2-x11-forwarding-linux","status":"publish","type":"post","link":"https:\/\/donguri3.net\/en\/server-tech\/virtualization-container-wsl\/wsl2-x11-forwarding-linux\/","title":{"rendered":"Trial and Error in Forwarding and Displaying Linux Server X Apps via WSL2"},"content":{"rendered":"<p>I wanted to SSH from WSL2 (Windows Subsystem for Linux) running on Windows to a Linux server (CentOS 7 in this case) and forward\/display a GUI app using X11 forwarding. I tried <code>ssh -Y<\/code>, but it wasn&#8217;t quite as straightforward as I hoped.<br \/>This article summarizes the trail of trial and error I went through until I was finally able to display <code>xclock<\/code>, along with the key configuration points to make it work properly.<\/p>\n<hr \/>\n<h4>Environment<\/h4>\n<ul>\n<li><strong>Local<\/strong>: Windows 11 + WSL2 (Ubuntu 22.04)<\/li>\n<li><strong>Remote<\/strong>: CentOS 7<\/li>\n<li><strong>Goal<\/strong>: Display a GUI app (e.g., xclock) on the WSL side using <code>ssh -Y<\/code><\/li>\n<\/ul>\n<hr \/>\n<h4>First Error Encountered<\/h4>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">$ ssh -X &lt;centos7&gt;\nWarning: No xauth data; using fake authentication data for X11 forwarding.\nX11 forwarding request failed on channel 0<\/pre>\n<p>Even after trying various information found by searching for this message, <code>xclock<\/code> would not appear.<\/p>\n<hr \/>\n<h4>Checking the WSL Side<\/h4>\n<p>First, I checked if the X server on the WSL side was running.<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">$ echo $DISPLAY\n:0\n$ xclock<\/pre>\n<p>If <code>xclock<\/code> appears here, it is proof that the WSL X server (such as WSLg or VcXsrv) is running. However, the following warning may sometimes appear:<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">Warning: Missing charsets in String to FontSet conversion<\/pre>\n<p>Since this is font-related, it can be ignored and will not affect operation.<\/p>\n<p>Note: When I tried it on another machine, it didn&#8217;t work if the WSL (WSLg) version was too old. In that case, please update WSL.<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">wsl \u2014update<\/pre>\n<p>\u203bPlease run this in Command Prompt or PowerShell with administrator privileges.<\/p>\n<p>Restart WSL after the update and check again.<\/p>\n<hr \/>\n<h4>Organizing <code>.Xauthority<\/code><\/h4>\n<p>Next, I initialized and organized <code>.Xauthority<\/code> using <code>xauth<\/code>.<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">cp ~\/.Xauthority ~\/.Xauthority.bak\nxauth remove $(xauth list | awk &#039;{print $1}&#039;)\nxauth add localhost:10.0 . $(mcookie)<\/pre>\n<hr \/>\n<h4>Important Configuration on the Remote (CentOS 7) Side<\/h4>\n<p>This is the most critical point.<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">sudo vi \/etc\/ssh\/sshd_config<\/pre>\n<p>Make sure to check and modify the following settings:<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">X11Forwarding yes\nX11UseLocalhost no<\/pre>\n<p>If you leave this as:<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">X11UseLocalhost yes<\/pre>\n<p>forwarding from WSL will continuously fail. In fact, a large number of errors like the following were appearing in the logs:<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">error: Failed to allocate internet-domain X11 display socket.<\/pre>\n<p>After configuring, restart <code>sshd<\/code>:<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">sudo systemctl restart sshd<\/pre>\n<hr \/>\n<h4>\u2705 Allowing DISPLAY<\/h4>\n<p>Configure the WSL side to accept connections:<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">export DISPLAY=:0\nxhost +<\/pre>\n<p>This also allows connections from external sources (CentOS 7).<\/p>\n<hr \/>\n<h4>\ud83d\udd04 Final Connection and Verification<\/h4>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">ssh -Y &lt;centos7&gt;\necho $DISPLAY\nxclock<\/pre>\n<p><a href=\"https:\/\/donguri3.net\/wp-content\/uploads\/2025\/07\/5c5768fd6fcc80c4dec7a9452ad76989.png\"><img decoding=\"async\" class=\"aligncenter size-full wp-image-1821\" src=\"https:\/\/donguri3.net\/wp-content\/uploads\/2025\/07\/5c5768fd6fcc80c4dec7a9452ad76989.png\" alt=\"xclock\" width=\"175\" height=\"199\" \/><\/a><br \/>\n<code>xclock<\/code> finally appeared! \ud83c\udf89<\/p>\n<hr \/>\n<h4>\ud83d\udca1 Summary<\/h4>\n<ul>\n<li><code>X11UseLocalhost no<\/code> is mandatory<\/li>\n<li>Manage <code>.Xauthority<\/code> with <code>xauth<\/code><\/li>\n<li>Allow connections with <code>xhost +<\/code><\/li>\n<li>Ideally, the <code>DISPLAY<\/code> value is automatically set to <code>:0<\/code> on the WSL side and <code>localhost:10.0<\/code> or similar on the remote side<\/li>\n<li>Once GUI apps can be displayed, <code>gedit<\/code>, <code>xeyes<\/code>, <code>firefox<\/code>, etc., will work similarly<\/li>\n<\/ul>\n<hr \/>\n<h4>\ud83d\udcdd Bonus<\/h4>\n<p>Font warnings when running <code>xclock<\/code> can be resolved with the following package:<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">sudo yum install -y xorg-x11-fonts-misc<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>I wanted to SSH from WSL2 (Windows Subsystem for Linux) running on Windows to a Linux server (CentOS 7 in this [&hellip;]<\/p>\n","protected":false},"author":4,"featured_media":1828,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_locale":"en_US","_original_post":"https:\/\/donguri3.net\/?p=1812","footnotes":""},"categories":[1171],"tags":[136,105,352,100,365,10],"class_list":["post-5111","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-virtualization-container-wsl","tag-centos7","tag-linux","tag-ubuntu","tag-ubuntu-22-04","tag-wsl2","tag-server","en-US"],"_links":{"self":[{"href":"https:\/\/donguri3.net\/wp-json\/wp\/v2\/posts\/5111","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/donguri3.net\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/donguri3.net\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/donguri3.net\/wp-json\/wp\/v2\/users\/4"}],"replies":[{"embeddable":true,"href":"https:\/\/donguri3.net\/wp-json\/wp\/v2\/comments?post=5111"}],"version-history":[{"count":1,"href":"https:\/\/donguri3.net\/wp-json\/wp\/v2\/posts\/5111\/revisions"}],"predecessor-version":[{"id":5114,"href":"https:\/\/donguri3.net\/wp-json\/wp\/v2\/posts\/5111\/revisions\/5114"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/donguri3.net\/wp-json\/wp\/v2\/media\/1828"}],"wp:attachment":[{"href":"https:\/\/donguri3.net\/wp-json\/wp\/v2\/media?parent=5111"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/donguri3.net\/wp-json\/wp\/v2\/categories?post=5111"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/donguri3.net\/wp-json\/wp\/v2\/tags?post=5111"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}