This gist provides a summary on how to accomplish the following tasks:
- Access WSL2 using putty
- Run Eclipse on WSL2 Ubuntu, displaying the Eclipse UI on VcXsrv running on Windows
- Connecting to VcXsrv directly from WSL2
- Using SSH X11 forwarding, with network connection initiated from Windows to WSL2 Ubuntu, which is particularly useful on company laptops that refuse all incoming network connections on Windows.
-
Prerequisites:
- WSL2 up and running
- Putty, Plink & PuttyGen installed on Windows
-
WSL2 Ubuntu: Install & configure OpenSSH
-
sudo apt install openssh-server
-
Edit
/etc/ssh/sshd_config
:X11Forwarding yes X11DisplayOffset 10 X11UseLocalhost no
-
sudo ssh-keygen -A
-
sudo service ssh start
-
-
Auto-start SSH daemon:
- WSL2 Ubuntu:
mkdir -p ~/bin ; echo "sudo service ssh start" >> ~/bin/startup.sh
- Windows: Create scheduled task that runs on user logon, running
C:\Windows\System32\bash.exe
with arguments/home/<user>/bin/startup.sh
- WSL2 Ubuntu:
-
Windows: Configure SSH public key authentication using PuttyGen:
- See https://www.puttygen.com/#How_to_use_PuTTYgen for general instructions
- Run PuttyGen
- Generate new key pair, or convert existing key pair
- Save private key to ppk file; this will used later when connecting to WSL2 Ubuntu using Putty or PLink
- Add the SSH public key to
~/.ssh/authorized_keys
on WSL2 Ubuntu
-
Windows: Create putty profile to connect to WSL2 Ubuntu:
- Session
- Host Name: localhost
- Port: 22 (or whatever OpenSSH port you configured on WSL2 Ubuntu)
- Connection -> Data:
- Auto-login username:
<your user name>
- Auto-login username:
- Connection -> SSH -> Auth:
- Private key file for authentication:
<key file generated by PuttyGen in step #2>
- Private key file for authentication:
- Connection -> SSH -> X11:
- Enable X11 forwarding (if you want to start X11 programs)
- X display location: 127.0.0.1:0.0 (this should match whatever DISPLAY value is shown in VcXsrv logs)
- Session
-
Windows: Install & configure VcXsrv:
- Download & install https://sourceforge.net/projects/vcxsrv/
- Copy config.xlaunch as shown below to the Startup folder (Win+R:
shell:startup
) - Launch config.xlaunch to start the X Server manually for now
-
WSL2 Ubuntu: Install Eclipse & prerequisites:
sudo apt-get install openjdk-11-jdk
sudo apt-get install libgtk-3-0
- Download and unpack Eclipse for Linux to ~/eclipse
-
Windows: Eclipse shortcut using SSH X11 tunnel:
- Manually try starting Eclipse from Windows by running the following command:
plink.exe -batch -X -i <path to .ppk from step #2> <Ubuntu username>@localhost ~/eclipse/eclipse
- Copy
silent.vbs
andplink-silent.cmd
(see attached files) to the directory where PLink.exe is installed - Create a new shortcut that runs the following command:
C:\Windows\System32\cmd.exe /c "C:\<path to plink>\plink-silent.cmd -batch -X -i <path to .ppk from step #2> <Ubuntu username>@localhost ~/eclipse/eclipse"
- Double-click the shortcut; if all is well you should see the Eclipse UI after a couple of seconds
- Manually try starting Eclipse from Windows by running the following command:
-
Windows: Eclipse shortcut using direct XServer connection:
- Add the following lines to
~/.profile
on WSL2 Ubuntu (create file if it doesn't yet exist):
Note that having these lines inexport DISPLAY=$(awk '/nameserver / {print $2; exit}' /etc/resolv.conf 2>/dev/null):0 export LIBGL_ALWAYS_INDIRECT=1
.bashrc
won't work as.bashrc
is only loaded for interactive shells - Create a new shortcut that runs the following command:
C:\Windows\System32\wsl.exe -u <WSL2 user> -- bash -lc 'nohup ~/eclipse/eclipse' ^& sleep 1
- Add the following lines to
Many thanks for this. You've made me a happy man and changed how I will spend the majority of my day for the foreseeable future!
About 18 months ago I decided to switch from Eclipse, which I had been using successfully for what seems like 20 years, over to VSC.
Today, I made an honest assessment and finally admitted to myself that I hate it. It was also causing vmmem to grab all of my available RAM (~25GB) and making my machine unusable. I was happier with Eclipse. Since I'd become a fan of WSL2 Ubuntu I decided to search for how I could run Eclipse using WSL2 Ubuntu as my workspace. That led me here. I was getting a little frustrated because I didn't think the "Multiple windows" thing in XLaunch was working. So, I was starting with "One large window". I spent a bit of time trying to figure out how I could maximize the size of Eclipse in the X11 server window. Imagine my surprise when I started Eclipse without having launched "One large window" and the app came up looking like a regular Windows desktop app! Hahahaha. Yeah, I figured out that "Multiple windows" starts a background process and sits in the system tray.
A couple of thoughts here and perhaps to help others ...
"Copy config.xlaunch as shown below" I thought you forgot to add it because I wasn't seeing it "below". If I had noticed it was at the top or that WindowMode="MultiWindow" opened a process in the system tray I could have saved myself the last couple hours of fumbling around. LOL. Oh well.
I ended up saving the config.xlaunch to the XcXsrv install directory and modifying the XLaunch desktop shortcut to have a Target of "C:\Program Files\VcXsrv\xlaunch.exe" -run config.xlaunch
Step #7:
Eclipse will run much better with these ...
Assuming a typical Putty install, use C:\PROGRA~1\PuTTY\plink-silent.cmd as a path instead of C:\Program Files\PuTTY\plink-silent.cmd
Step #8:
When running a Groovy script in bash, following this config, I started getting:
java.awt.AWTError: Can't connect to X11 window server using 'NN.NN.NN.NN:0' as the value of the DISPLAY variable
where "NN.NN.NN.NN:0" is the value of DISPLAY as determined by the awk command
I cured it simply by opening up the permissions in the Windows Firewall for the vcxsrv.exe executable.