How do I set the DISPLAY variable on Linux?
- How To Create Ssh Trust Connection Between Servers Or Client-Server To Connect Without Password?
- How to Implement Trusted Authentication Mechanisms in Linux, Unix and Windows servers, why?
- How to set up SSH & SSH Trust for the beginners?
- How to Set an Oracle Env. variable – ORACLE_HOME?
- Unix / Linux Secure Copy (SCP) usage and syntax
It is possible to use your computer at home or in the labs to login to the Client server machines and use cool graphical tools like xclock. The system that makes this possible is the X Windows System (X), it is the basis for all GUI application on the Client server machines. One of the design ideas behind X is the idea of remote displays, in much the same way a standard telnet login works. From another computer you connect to your sever over a network login and do all kinds of neat command line things remotely. X is the method that allows you to login to the server and use neat graphical things remotely.
Using Linux, and especially configuring Linux, normally require some insight, and we strongly suggest (to inexperienced linux users) to get some help from a system administrator.
In short, you must open up a shell (csh, bash, etc), so that it is possible to issue commands on Linux. Then you must enter the commands to set the environment variable, as explained in the setup-instructions.
In the following paragraphs I will give several examples of how to use X using UNIX based X servers such as Xfree86. For other OSes refer to the user manual of your X server to find how to do similar things. First lets load an X server under Linux and see some of the details inside (further details of how to get this far are at Xfree86):
This starts the server and by default starts a single xterm. An xterm is just a simple X client to display text in, usually a login shell. Assuming you are running bash you can look at your environment variables (EV) by typing “set”. Environment variables store useful information for programs defaults or system state. If you look at your EV you will see a variable called “DISPLAY” this variable stores the address for X clients to connect to. These addresses are in the form:
A typical example would be:
or
192.168.0.12:0.0
I said earlier that it is possible to have more than one X server running at a time. In this case the displayname would be something like
or
192.168.0.12:1.0
or
or
192.168.0.12:0.1
depending on how its done.
When the X clients start the look at the DISPLAY EV to see where to connect to by default. One way to do remote displaying would be to set this EV to a remote X server.
or
$ export DISPLAY=192.168.0.12:0.0
Or you can set this in .bashrc file like this to have it automatically keep it with your client computer during your ssh login.
export DISPLAY=${CLIENTIP}:0.0
Other forms of DISPLAY exist, but this will do for our purposes.
Telling the Client
The client program (for instance, your graphics application) knows which display to connect to by inspecting the DISPLAY environment variable. This setting can be overridden, though, by giving the client the command line argument -display hostname:0 when it’s started. Some examples may clarify things.
Our computer is known to the outside as light, and we’re in domain uni.verse. If we’re running a normal X server, the display is known as
light.uni.verse:0. We want to run the drawing program xfig on a remote computer, called dark.matt.er, and display its output here on light.
If you have csh running on the remote computer:
dark% xfig &
Or alternatively:
If you have sh running on the remote computer:
dark$ export DISPLAY
dark$ xfig &
Or alternatively:
Or, of course, also:
It seems that some versions of telnet automatically transport the DISPLAY variable to the remote host. If you have one of those, you’re lucky, and it’s automatic. If not, most versions of telnet _do_transport the TERM environment variable; with some judicious hacking it is possible to piggyback the DISPLAY variable on to the TERM variable.”
Then you can run your cool X application and its display will be on mymachine.mynet.uidaho.edu.
Another way to do remote display is by a command line option that all X applications have: “-display [displayname]“. To run your cool X application:
This does the exact same as before.
The previous demonstrations rely on whether your X server is allowing connections from remote hosts. The following command allows connections from all hosts (run on machine that the X server is running on (mymachine.mynet.uidaho.edu)):
To allow connections from single hosts at a time:
ssh is a neat remote login tool that in addition to having secure encrypted transmissions auto forwards your X DISPLAY EV if your are running it under an X Server. ssh allows a easy, no hassle, way to do all of the stuff we have discussed so far. The ssh documentation has more detailed information on how to get this working.

I recently came across your blog and have been reading along. I thought I would leave my first comment. I don’t know what to say except that I have enjoyed reading. Nice blog. I will keep visiting this blog very often.
Joannah
http://linuxmemory.net