xhost+ : How to Fix “Cannot Open Display” Error While Launching GUI on Remote Server

by SathiyaMoorthy on June 25, 2010

Question: When I try to launch any GUI application on a remote server, I’m getting the “cannot open display:” error, as shown below. How do I fix this?

For example, while launching the gedit on remote server, I got the following message.

(gedit:3658): Gtk-WARNING **: cannot open display: 

I get similar message when I try to open any GUI application. For example, launching Oracle Installer on remote server also gives the “cannot open display” error.

Answer: You can fix the “cannot open display” error by following the xhost procedure mentioned in this article.

1. Allow clients to connect from any host using xhost+

Execute the following command to disable the access control, by which you can allow clients to connect from any host.

$ xhost +
access control disabled, clients can connect from any host

2. Enable X11 forwarding

While doing ssh use the option -X to enable X11 forwarding.

$ ssh username@hostname -X

Enable trusted X11 forwarding, by using the -Y option,

$ ssh username@hostname -Y

3. Open GUI applications in that host

After opening ssh connection to the remote host as explained above, you can open any GUI application which will open it without any issue.

If you still get the “cannot open display” error, set the DISPLAY variable as shown below.

$ export DISPLAY='IP:0.0'

Note: IP is the local workstation’s IP where you want the GUI application to be displayed.


Linux Sysadmin Course Linux provides several powerful administrative tools and utilities which will help you to manage your systems effectively. If you don’t know what these tools are and how to use them, you could be spending lot of time trying to perform even the basic administrative tasks. The focus of this course is to help you understand system administration tools, which will help you to become an effective Linux system administrator.
Get the Linux Sysadmin Course Now!

If you enjoyed this article, you might also like..

  1. 50 Linux Sysadmin Tutorials
  2. 50 Most Frequently Used Linux Commands (With Examples)
  3. Top 25 Best Linux Performance Monitoring and Debugging Tools
  4. Mommy, I found it! – 15 Practical Linux Find Command Examples
  5. Linux 101 Hacks 2nd Edition eBook Linux 101 Hacks Book

Bash 101 Hacks Book Sed and Awk 101 Hacks Book Nagios Core 3 Book Vim 101 Hacks Book

{ 8 comments… read them below or add one }

1 hari June 25, 2010 at 9:10 am

is
# xhost -
will block from using X server from remote login to this system?

for ex:
system1 # xhost -
system2 # ssh -X system1
system1 # gedit new.txt
it opening a new file, it not blocking X server.

2 Jeff June 25, 2010 at 9:39 am

love this site, love these articles but xhost? pfft!

hari, when you’re X11 forwarding, you aren’t using xhost for X authentication. the client is using xauth authentication mechanism. the server and client share a secret “cookie”(xauth list to see yours)…. google xauth howto comes up with a lot of references

3 thib June 25, 2010 at 11:53 am

Unless the network environment is entirely controlled, xhost is a very bad idea [1]. Prefer xauth [2] or other mechanisms. See the Remote X Apps mini-HOWTO for details [3]. (My understanding.)

1: http://www-it.desy.de/systems/services/x11/xsec.html
2: http://www.acm.uiuc.edu/workshops/cool_unix/xauth.html
3: http://tldp.org/HOWTO/Remote-X-Apps.html

4 Slappy June 25, 2010 at 6:37 pm

xhost is a security nightmare. Just use “ssh -X name@serveripaddress”, then type the name of the progam you want to use.

5 Pavi October 17, 2011 at 6:03 am

Really good information. It worked for me.
but If I want to open GUI application on my host which is installed on other host.
Suppose no browsers are installed on my host and if i want to open browser which is installed on other host, how can i do this.
In this case, which host’s IP will be considered for opening sites?mine or accessed?
i hope you understand, what i want to know.
Thanks

6 naveen January 4, 2012 at 7:53 am

rly good solution ..its worked for me

7 Rashid December 6, 2013 at 3:23 am

i install geany and when run it got below error. even i update gtk2 and all depended lib. also export DISPLAY=’IP:0.0′ with local ip, can any one help me to remove this error to run geany
#geany
Geany: cannot open display

8 Peter June 29, 2014 at 3:26 am

xhost+ solved it for me, using vnc into a Wheezy headless server.

Thank you for the fix, this has been annoying me for a while now!

Leave a Comment

Previous post:

Next post: