Opening GUI Applications as root or sudo users in Linux often we see errors . Gtk-WARNING : Cannot open Display.
sudo: unable to resolve host ethicalhackx No protocol specified Failed to connect to Mir: Failed to connect to server socket: No such file or directory Unable to init server: Could not connect: Connection refused (gedit:7697): Gtk-WARNING **: cannot open display: :0
Here is simple step to solve this error by the xhost procedure
- Open Terminal.
- Now you are able to run programs like gedit nautilus via
sudo geditand more
xhost + allows clients to connect from any host using xhost +
The following command will 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
How To Enable X11 forwarding
While doing ssh use the option -X to enable X11 forwarding.
$ ssh username@hostname -X
How To Enable trusted X11 forwarding, by using the -Y option,
$ ssh username@hostname -Y
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.
When running UXTERM or XTERM just issue
The variable will be there. Then just set it and export it.