Got Error "Gtk-Warning **: Cannot Open Display:" When Using X11

Got Error "Gtk-Warning **: Cannot Open Display:" When Using X11
  1. What the environment like:
    Local host is Ubuntu 18.04, remote host is Debian 9. There are some virtual machin on remote host.
  2. What I found:
    Today I want to management virtual machines on remote host, by using ssh -x as usual. But this time I logon, it note xhost: unable to open display "". And when I execute virt-manager, it shows like this:
Unable to init server: Could not connect: Connection refused
Unable to init server: Could not connect: Connection refused
Unable to init server: Could not connect: Connection refused

(virt-manager:16045): Gtk-WARNING **: cannot open display: 
  1. What I tried to solve this problen: First I checked my local host's /etc/ssh/ssh_config and make sure it have configured like below:
ForwardAgent yes
ForwardX11 yes
ForwardX11Trusted yes

And then check the remote host's /etc/ssh/ssh_config and make sure it have configured like below:

 X11Forwarding yes
 X11DisplayOffset 10
 PrintMotd no
 PrintLastLog yes
 TCPKeepAlive yes

And then I execute virt-manager, it still shows like below:

Unable to init server: Could not connect: Connection refused
Unable to init server: Could not connect: Connection refused
Unable to init server: Could not connect: Connection refused

(virt-manager:16045): Gtk-WARNING **: cannot open display: 

Then I tried few commands like below, it seemes useless.

$ sudo vncserver

New 'My_Local_Host:15 (root)' desktop at :15 on machine My_Local_Host

Starting applications specified in /etc/X11/Xvnc-session
Log file is /root/.vnc/My_Local_Host:15.log

Use xtigervncviewer -SecurityTypes VncAuth -passwd /root/.vnc/passwd :15 to connect to the VNC server.
$ export DISPLAY=localhost:15
$ xhost +
xhost:  unable to open display "localhost:15"

Finally I installed gksu and tried to open virt-manager by it, but it still useless:

gksu virt-manager 

(gksu:17242): Gtk-WARNING **: cannot open display: localhost:15

Can you give me some advice? Thank you!

1
Sophia Al-Mansoor
Author

Sophia Al-Mansoor

Sophia analyzes international trade, startup ecosystems, retail transformation, and supply chain logistics for modern digital publications.