Cannot Open Display error can occur on a Linux system when trying to open a GUI application, especially if opening it from the command line. It can also pop up if you are trying to use X11 forwarding via SSH to a remote system. The good news is that this error is relatively easy to fix, whether you are getting it when accessing a local application or a remote server. In this tutorial, we will cover the steps necessary to fix the
Cannot Open Display error on Linux.
In this tutorial you will learn:
- How to check the
- How to set the
- How to enable X forwarding in SSH
|Requirements, Conventions or Software Version Used
|Any Linux distro
|Privileged access to your Linux system as root or via the
# – requires given linux commands to be executed with root privileges either directly as a root user or by use of
$ – requires given linux commands to be executed as a regular non-privileged user
A great way to test if your system has the DISPLAY variable configured correctly is to execute
xeyes. This small program is on most Linux distros by default and is a quick and handy way to test for display issues.
Fixing the ‘Cannot Open Display’ Error on Linux
- When receiving the
Cannot Open Displayerror, the first thing you should check is the value of your
DISPLAYvariable, and verify that it is even set at all.
$ echo DISPLAY
If this command shows no output or gives you an error, then your variable has not been set or is set incorrectly.
- To set the DISPLAY variable, we will use the following command:
$ export DISPLAY=:0
Note that your DISPLAY value may need to be different, like
:0.0. It depends on your system and configuration. After setting it, check again to make sure that your variable is now set correctly, and then try opening
xeyesto verify the fix:
$ echo DISPLAY $ xeyes
- If you are attempting to run a GUI based application from a remote server, you need to make sure that your SSH connection has X11 forwarding enabled. Try disconnecting from the session, and when reconnecting, use the
-Xoption in your SSH login command:
$ ssh -X username@remote-server
Alternatively, try using a different application to share the desktop screen such as X11vnc.
- If you still cannot use X11 forwarding via SSH, then make sure that the server has X11 forwarding enabled in the sshd config file:
$ grep X11Forwarding /etc/ssh/sshd_config
The line will look like this if it is enabled:
- The next thing to check is to see if the host has proper permissions to use X11 forwarding. We can do this by executing the
xhostcommand on the server. Use the following command to disable access control and allow all hosts to utilize X11 forwarding. Then try to connect once again and open the GUI application – this will tell you whether or not it is a permission issue.
$ xhost + access control disabled, clients can connect from any host
In this tutorial, we saw how to fix the
Cannot Open Display error on a Linux system. This is a common issue that is usually caused by a misconfigured DISPLAY variable or a problem with an X11 forwarding setting if using SSH. Fortunately, the steps here make it a pretty easy fix, and should get your GUI based apps running again in no time.