0

I have a Raspberry Pi 4 set up with x11 enabled in the sshd_config. I connect to the Pi with ssh and the -X argument set. When I try to open an application, lets say gedit, it gives me the error

Unable to init server: Could not connect: Connection refused (gedit:4795): Gtk-WARNING **: 16:19:14.250: cannot open display: localhost:0.0

Running gedit locally on the subsystem works perfectly.

Troubleshooting through Superuser and Google does not find me a solution to this problem.

I am also trying to run gparted as sudo, which is throwing me the same error

Maarten
  • 485

2 Answers2

1

After some more troubleshooting and googling I stumbled across this post. The command export DISPLAY="127.0.0.1:10.0" fixed my issue and succesfully opened gedit.

Maarten
  • 485
1

Check your shell startup files (.bash_profile, etc.) for something that might be setting DISPLAY incorrectly. If SSH sets up X forwarding, then it'll set DISPLAY to a correct value for you. There should be no need for you to set up DISPLAY yourself when forwarding X through SSH.

When an ssh connection creates an X11 forward, then the SSH server will set up a DISPLAY environment variable for any ssh sessions made through that connection. Typically, the value of display will be something like localhost:10.0. You might see an IP address instead of "localhost" if sshd is compiled to do that. The number "10" might be 11, 12, etc. if display 10 was already in use.

The number 10 comes from the sshd configuration option X11DisplayOffset. The default is 10, but it could be set to another number if someone had a reason to.

You say that gtk is trying and failing to connect to localhost:0.0. There are two reasons that could be happening:

  1. X11DisplayOffset is set to 0 on the server (the raspberry pi?) for some reason, AND the forwarding isn't working for some reason.
  2. Something in your shell startup files (.bash_profile, etc.) is overriding the DISPLAY value set by ssh with another, incorrect value.

You say that setting DISPLAY to 127.0.0.1:10.0 works. This means that sshd is probably using the default X11DisplayOffset. This implies that your problem is #2: Something in your shell startup files is incorrectly setting DISPLAY to localhost:0.0, overriding the correct DISPLAY value which the ssh server ought to be creating.

Kenster
  • 8,620