
X11 allows you to run GUI applications on a remote server while viewing them on your local machine. This guide will help you set the DISPLAY variable, enable X11 forwarding in Linux without making any confusions.
What is the DISPLAY variable?
The DISPLAY variable indicates where to show an application's GUI output, ensuring it appears on your local screen when running remotely.
Steps to Set Display Variable in Linux
Before making changes, check the current value of your DISPLAY variable!!
echo $DISPLAY
The variable might not be set or configured correctly if you see something like localhost:10.0 or a blank output.
If the DISPLAY variable is empty or incorrect, run the command to set the DISPLAY variable:
For Bash Shell Users:
export DISPLAY=localhost:10.0

For C-Shell (csh) Users:
setenv DISPLAY localhost:10.0
After setting the DISPLAY variable, verify it using the below command again:
echo $DISPLAY
Steps to Enable X11 Forwarding in SSH
To use X11 forwarding when connecting to a remote server, you must enable it in your SSH settings.
- Open the SSH configuration file on your local machine:
nano /etc/ssh/ssh_config
- Ensure the following lines are present and uncommented in the /etc/ssh/ssh/ssh_config file:
ForwardX11 yes
ForwardX11Trusted yes

- Save the changes and restart your SSH session.

Testing X11 Forwarding in Linux
To connect to the remote server with X11 forwarding enabled, execute the following command after replacing the exact values (username, IP/hostname, password) of your remote machine:
ssh -X username@remote_serverIP

Test the setup by running a GUI application, such as gedit:
gedit
The configuration is successful if the GUI application appears on your local screen.

Following this guide helps you set the DISPLAY variable, enable X11 forwarding, and allow you to connect remote GUI applications to run on your local machine easily. As a final tip, please ensure that your local machine has an X server installed (e.g., XQuartz for macOS, Xming for Windows) if any errors appear in between the setup.