with explaintions in English
Rather than disabling access control on VcXSrv, you should use the .Xauthority file to share keys between your X11 clients and the VcXSrv X11 server. The .Xauthority contains a collection of authorization keys indexed by the DISPLAY . You'll need to setup this file with a key for your particular Windows host and share that file between the VcXSrv and your X11 clients running on your WSL2 distro. To setup this, follow these steps:
# get the IP ADDRESS NN.NN.NN.NN for your host machine. You may have to try a number
# of different ways. Some are listed in this page. Others can be found on Microsoft's
# support pages.
export DISPLAY=NN.NN.NN.NN:0
# IF you have docker installed on your windows host, you can just set the display to
# export DISPLAY=host.docker.internal:0
sudo apt install -y xauth coreutils gawk gnome-terminal
xauth list # this should be an empty list
magiccookie=$(echo '{some-pass-phrase}'|tr -d '\n\r'|md5sum|gawk '{print $1}')
xauth add "$DISPLAY" . "$magiccookie"
# Now check to see if it was added by doing
xauth list # you should see the newly added entry for host.docker.internal
# The line below assumes that you've installed your windows into the default location
# C:\Windows folder. We use the cmd.exe to grab the location of the Windows' UserProfile
# folder
userprofile=$(wslpath $(/mnt/c/Windows/System32/cmd.exe /C "echo %USERPROFILE%" | tr -d '\r\n'))
cp ~/.Xauthority "$userprofile"
We want to run VcXSrv.exe with these args:
vcxsrv.exe -multiwindow -clipboard -wgl -auth {.XAuthority file} -logfile {A Log file} -logverbose {int log level}
From above, we copied the .Xauthority file to your Windows 10 userprofile directory which will be something like /mnt/c/Users/{WindowsUserName}/.Xauthority which means our desired command line is:
%ProgramFiles%\VcXsrv\vcxsrv.exe -multiwindow -clipboard -wgl -auth "%USERPROFILE%\.Xauthority" -logfile "%USERPROFILE%\VcXSrv.log" -logverbose 5
We use the Windows 10 environment variables %ProgramFiles% and %USERPROFILE% to get the location of the Program Files folder and UserProfile folder under Windows 10. Feel free to omit the logfile and logverbose options if you're not debugging any issues. So you can just do:
%ProgramFiles%\VcXsrv\vcxsrv.exe -multiwindow -clipboard -wgl -auth "%USERPROFILE%\.Xauthority"
To create the shortcut, navigate to where VcXSrv.exe is installed. The default location of this is
%ProgramFiles%\VcXSrv\VcXSrv.exe
In the explorer file window, right click on the VcXSrv.exe and click "Create Shortcut" . This will create a shortcut on your desktop.
Right click over the created shortcut icon, and select properties.
In the Shortcut tab, append the arguments above after the executable . It should look something like:
%ProgramFiles%\VcXsrv\vcxsrv.exe -multiwindow -clipboard -wgl -auth "%USERPROFILE%\.Xauthority"
In the General tab of the Properties dialog, change the name to be "VcXSrv with XAuthority" .
Click ok.
Now you can start the X11 server by double clicking on the shortcut.
If you wish to have the X11 server started at startup, follow the instructions here: https://support.microsoft.com/en-us/windows/add-an-app-to-run-automatically-at-startup-in-windows-10-150da165-dcd9-7230-517b-cf3c295d89dd
Now back in the WSL distro terminal, you should be able to run the gnome-terminal or other X11 client and have it display securely
on the VcXSrv X11 server running on the Windows host.
export DISPLAY=host.docker.internal:0
gnome-terminal
These steps worked as of Mar 2021 on Windows 10 Pro Version 20H2
Steps to setup the server-side on windows:
At this point the server-side is ready. Now it's time to configure the client:
Open a terminal and find the IP of the windows host machine with this command:
export DISPLAY=$(/sbin/ip route | awk '/default/ { print $3 }'):0
https://github.com/microsoft/WSL/issues/4106#issuecomment-634778111.
run: echo $DISPLAY
to see the IP.
nc -v IP_FROM_PREVIOUS_STEP 6000
//make sure to remove the appended ":0" after the IP.Source: alextsil/ steps_gui_wsl2_xserver.txt
or check out Using VcXsrv Windows X Server, add VcXsrv windows server exe to the Firewall ^ , create a Shortcut (.lnk) to the VcXsrv.exe and put it to the Autostart in your Startmenu .
And open a Terminal like at the Description from Alexil and make do the rest so that the display is exported
I added instructions for using xauth with VcXSrv. Disabling access control is a really bad idea as anyone on your network can log any keys you enter or mouse movements etc simply by connectiong to your VcXSrv . Its very easy to setup a .Xauthority that you can share between different clients allowing them to connect to your server. This will at least allow you to control who can connect to your server.
all informations are well, for short using and for make a hard connection in security way, alone the User/Admin decide what he use .. so, thumps up :)
but, you coud add to the commandline the variable for the user instead "{WindowsUserName}" should you use " %USERPROFILE%\.Xauthority"
then is more easy for the peoples to use your cmdline,
maybe could you update your cmdline ?
Last edit: blackcrack 2021-03-24
Done. Great suggestion!
my 2 cents, I was initially using other instruction, but also found this one and tried to set up xauth, so
if someone deal with same, use
touch ~/.Xauthority
export DISPLAY="$(cat /etc/resolv.conf | grep nameserver | awk '{ print $2 }'):0.0"
xauth add $DISPLAY . $magiccookie
notice dot before $magiccookie
thanks for article
Last edit: Solopov Sergey 2021-03-29
Thanks for the feedback. I fixed the typo in the xauth add as it was missing the '.' . As for the IP address, I'll leave it as an exercise to the reader to get the correct address. It seems that right one will depend upon both your VcXSrv and your particular WSL2 setup. Since I use docker, the host.docker.internal hostname works well and in my case, its mapped to the IP address associated with the ethernet connection WHICH IS NOT what the /etc/resolv.conf gives.
I added a gist on github that will walk you through setting up your xauthority file with WSL2. It will ask that you create a WSLENV variable to export a couple of Windows Environment Variables to your WSL2 distro. You'll need to determine the IP address which I obtained the one associated with my PC's ethernet connection using Window's "Network and Internet settings".
cd to your USERPROFILE folder (e.g. cd /mnt/c/Users/{WindowsUserName})
export DISPLAY=NN.NN.NN.NN:0
bash -c "$(curl "https://gist.githubusercontent.com/zuut/c9c3b95b90d9620d4805c30e0b4791cc/raw/66d2d44e9843c1906024f4b6135de50f868f62c7/wsl2SetupForVcXSrv.sh")"
NOTE: Download the zip containing the shortcut plus the script above and extract it and run in a directory. https://gist.github.com/zuut/c9c3b95b90d9620d4805c30e0b4791cc/archive/35ed038f1495179348878d0279a06952a103c18e.zip
Last edit: Joe On Hotmail 2021-04-13
do you have an Github.com account ?
Joe told:
then could you make a cmd/batch file and upload it, this could linking in this sourceforge wiki.. or like me : setup/update batch (btw; this tread is for conversations, be pm's only for wz *bg* ;) )
best
Last edit: blackcrack 2021-03-31