Linux - DISPLAY (environment variable)
Table of Contents
1 - About
The magic word in the X window system is DISPLAY.
The DISPLAY environment variable instructs an X client which X server it is to connect to by default.
The X display server install itself normally as display number 0 on your local machine. In Putty, the “X display location” box reads localhost:0 by default.
A display consists (simplified) of:
- a keyboard,
- a mouse
- and a screen.
A display is managed by a server program, known as an X server. The server serves displaying capabilities to other programs that connect to it.
The remote server knows where it have to redirect the X network traffic via the definition of the DISPLAY environment variable which generally points to an X Display server located on your local computer.
The SSH protocol has the ability to securely forward X Window System applications over an encrypted SSH connection, so that you can run an application on the SSH server machine and have it put its windows up on your local machine without sending any X network traffic in the clear. $DISPLAY on the remote machine should point to localhost. SSH does the forwarding.
2 - Articles Related
3 - The environment variable
3.1 - Value
The value of the display environment variable is:
- hostname is the name of the computer where the X server runs. An omitted hostname means the localhost.
- D is a sequence number (usually 0). It can be varied if there are multiple displays connected to one computer.
- S is the screen number. A display can actually have multiple screens. Usually there's only one screen though where 0 is the default.
3.2 - Example of values
localhost:4 gerardnico.com:0 :0.0
- hostname:D.S means screen S on display D of host hostname; the X server for this display is listening at TCP port 6000+D.
- host/unix:D.S means screen S on display D of host host; the X server for this display is listening at UNIX domain socket /tmp/.X11-unix/XD (so it's only reachable from host).
- :D.S is equivalent to host/unix:D.S, where host is the local hostname.
3.3 - How to set the DISPLAY variable
Setting the DISPLAY variable, depend of your shell
- Bourne, Bash or Korn shell:
$ export DISPLAY=local_host:0.0
- C shell
% setenv DISPLAY local_host:0.0
In this example, local_host is the host name or IP address of the local computer that you want to use to display for instance an installation screen such as Oracle Universal Installer.