0

I ssh to a remote host (without X forwarding).

In the shell created by sshd on the remote host, why can't I start a GUI program on the default $DISPLAY

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

(eog:31542): Gtk-WARNING **: 23:11:16.793: cannot open display: 

$ echo "$DISPLAY"

$

while specifying explicitly $DISPLAY=:0 creates a window on the remote host?

$ DISPLAY=:0 eog

(eog:31546): dbind-WARNING **: 23:11:42.415: Error retrieving accessibility bus address: org.freedesktop.DBus.Error.ServiceUnknown: The name org.a11y.Bus was not provided by any .service files

Isn't :0 the default value of $DISPLAY?

  • Are you SSH port forwarding the X port to your local host? – Peschke Mar 15 at 3:32
  • Why would an env has default value? If it doesn't exist, then it doesn't exist, and so you can't retrieve it. If it exist, then it has some value, might be empty string, but it has some value. – 炸鱼薯条德里克 Mar 15 at 3:36
  • Really don't know what do you mean by "default $DISPLAY". Please use env command to check all your envs. – 炸鱼薯条德里克 Mar 15 at 3:38
  • If you mean some sort of API that allows you to retrive a default value when some environment variable doesn't exist, I don't think xlib or xcb or any X client would use such API. So, if there's no $DISPLAY and you don't specify the display for your X client by some method, it simply fails to connect to any Display – 炸鱼薯条德里克 Mar 15 at 3:50
4

There is no default value for DISPLAY. If it’s not set, and you don’t specify a target display in some other way, X programs won’t be able to connect to a server.

This can be useful, e.g. to start a program with no X connection when you’re running inside an X session: temporarily clearing DISPLAY will ensure the X session isn’t found.

See How to change DISPLAY of currently running application for details of how DISPLAY is used, and Open a window on a remote X display (why "Cannot open display")? for details of the information required to connect to an X server.

  • That's exactly what I said in the comment. But I can't figure it out how is this useful for a X-based GUI program that you prevent it finding a Display? – 炸鱼薯条德里克 Mar 15 at 5:26
  • Some programs support X optionally; examples include Emacs (where you can achieve the same effect with -nw) and Wine. Clearing DISPLAY disables X support. It’s useful with Wine because running window-less tests is faster with no DISPLAY set. – Stephen Kitt Mar 15 at 5:40
  • Thanks. (1) I heard somthing like $DISPLAY defaults to :0.0. Did I mishear it? What is it instead? (2) "If you ssh onto some server, usually the display will be set automatically to the local X server, if there is one available. Otherwise, it will not be set at all (reason see terminal 3)." unix.stackexchange.com/a/503884. But your reply seems to say usually DISPLAY is no set – Tim Mar 15 at 10:30
  • (1) There is no default. (2) I’m not sure what suggests that to you, it’s usually set when you’re running in an environment where connecting to an X server makes sense. – Stephen Kitt Mar 15 at 11:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.