Have you ever wanted to run GUI applications on your Windows Subsystem for Linux 2 (WSL2) desktop? With X11 forwarding, you can seamlessly run Linux GUI applications on your WSL2 desktop, even if the application is installed on a remote Linux server. In this article, we will guide you through the process of setting up X11 forwarding from a remote Linux server to your WSL2 desktop.
What is X11 Forwarding?
X11 forwarding is a feature of the X Window System that allows you to run graphical applications on a remote Linux server and display them on your local machine. It enables you to use GUI applications on a remote server without the need for a graphical environment on your local machine. X11 forwarding works by forwarding the graphical output of the remote application to your local machine and relaying your input back to the remote server.
Prerequisites
Before we begin, make sure you have the following:
- A remote Linux server with X11 forwarding enabled
- A Windows machine with WSL2 installed
- A SSH client on your Windows machine (e.g., PuTTY)
Enabling X11 Forwarding on the Remote Linux Server
To enable X11 forwarding on the remote Linux server, you need to modify the SSH server configuration file. Here's how:
- Connect to your remote Linux server using SSH.
- Edit the SSH server configuration file using a text editor (e.g., nano or vi). For example, run the command
sudo nano /etc/ssh/sshd_config. - Find the line that says
#X11Forwarding noand change it toX11Forwarding yes. - Save the changes and exit the text editor.
- Restart the SSH server for the changes to take effect. Run the command
sudo service ssh restart.
Setting Up X11 Forwarding on WSL2
Now that X11 forwarding is enabled on the remote Linux server, we need to set it up on our WSL2 desktop. Here's how:
- Open a terminal in your WSL2 environment.
- Install an X server on your Windows machine. We recommend using VcXsrv, which is a popular and easy-to-use X server for Windows. You can download it from the official website: https://sourceforge.net/projects/vcxsrv/.
- Launch VcXsrv and configure it to allow connections from the local machine.
- Set the
DISPLAYenvironment variable in your WSL2 environment. Run the commandexport DISPLAY=localhost:0.0. - Test X11 forwarding by running a simple GUI application on the remote Linux server. For example, you can run
xeyesby executing the commandxeyesin your WSL2 terminal.
Using X11 Forwarding with SSH
Now that X11 forwarding is set up on both the remote Linux server and your WSL2 desktop, you can use SSH to connect to the remote server and run GUI applications. Here's how:
- Open a terminal in your WSL2 environment.
- Connect to the remote Linux server using SSH with X11 forwarding enabled. For example, run the command
ssh -X username@remote-server. - Once connected, you can run any GUI application installed on the remote server, and it will be displayed on your WSL2 desktop.
By enabling X11 forwarding on your remote Linux server and setting it up on your WSL2 desktop, you can easily run GUI applications on the remote server and display them on your local machine. This allows you to take advantage of the power and flexibility of Linux GUI applications even if you're using a Windows machine. Enjoy using X11 forwarding to enhance your Linux experience on WSL2!
| Reference | Link |
|---|---|
| VcXsrv | https://sourceforge.net/projects/vcxsrv/ |