85

When I run some programs over SSH, such as firefox &, I get an error

Error: no display specified 

I would like to open many displays, still showing the stdout of each program.

Initial Question: How can I specify the display to get a many-displayed program?

Pablo Santa Cruz gives me the following code as a solution. I do not understand it.

$ export DISPLAY=yourmachine.yourdomain.com:0.0

$ firefox &

What are yourmachine and yourdomain.com in the command?

Yuan Wen
  • 1,583
  • 3
  • 20
  • 38
Léo Léopold Hertz 준영
  • 134,464
  • 179
  • 445
  • 697

12 Answers12

88

The way that X works is the same as the way any network program works. You have a server of some description (in this case, the X display server) which runs on a specific machine, and you have X clients (like firefox) that try to connect to that server to get their information displayed.

Often (on "home" machines), the client and server run on the same box and there's only one server, but X is powerful enough that this doesn't need to happen. It was built with the server/client separation built in from the start.

This allows you to do such wondrous things such as log on to your box (in text mode) halfway around the planet, tell it that the display server is the box you're currently on and, voila, the windows suddenly start appearing locally.

In order for a client to interact with a user, it needs to know how to find the server. There are a number of ways to do this. Many clients allow the -display or --displayoption to specify it:

xeyes -display paxbox1.paxco.com:0.0

Many will use the DISPLAY environment variable if a display isn't specifically given. You can set this variable like any other:

DISPLAY=paxbox1.paxco.com:0.0; export DISPLAY # in .profile
export DISPLAY=paxbox1.paxco.com:0.0 # in your shell
DISPLAY=paxbox1.paxco.com:0.0 firefox & # for that command (shell permitting)

The first part of the DISPLAY variable is just the address of the display server machine. It follows the same rule as any other IP address; it can be a resolvable DNS name (including localhost) or a specific IP address (such as 192.168.10.55).

The second part is X-specific. It gives the X "display" (X server) number and screen number to use. The first (display number) generally refers to a group of devices containing one or more screens but with a single keyboard and mouse (i.e., one input stream). The screen number generally gives the specific screen within that group.

An example would be:

+----------------------------------------+
|paxbox1.paxco.com|                      |
+-----------------+                      |
|                                        |
|  +----------+----+  +----------+----+  |
|  |Display :0|    |  |Display :1|    |  |
|  +----------+    |  +----------+    |  |
|  |               |  |               |  |
|  | +-----------+ |  |               |  |
|  | |Screen :0.0| |  |               |  |
|  | +-----------+ |  |               |  |
|  | +-----------+ |  |               |  |
|  | |Screen :0.1| |  |               |  |
|  | +-----------+ |  |               |  |
|  | +-----------+ |  | +-----------+ |  |
|  | |Screen :0.2| |  | |Screen :1.0| |  |
|  | +-----------+ |  | +-----------+ |  |
|  | +-----------+ |  | +-----------+ |  |
|  | |Screen :0.3| |  | |Screen :1.1| |  |
|  | +-----------+ |  | +-----------+ |  |
|  | +-----------+ |  | +-----------+ |  |
|  | | Keyboard  | |  | |  Keyboard | |  |
|  | +-----------+ |  | +-----------+ |  |
|  | +-----------+ |  | +-----------+ |  |
|  | |   Mouse   | |  | |   Mouse   | |  |
|  | +-----------+ |  | +-----------+ |  |
|  +---------------+  +---------------+  |
|                                        |
+----------------------------------------+

Here you have a single machine (paxbox1.paxco.com) with two display servers. The first has four screens and the second has two. The possibilities are then:

DISPLAY=paxbox1.paxco.com:0.0
DISPLAY=paxbox1.paxco.com:0.1
DISPLAY=paxbox1.paxco.com:0.2
DISPLAY=paxbox1.paxco.com:0.3
DISPLAY=paxbox1.paxco.com:1.0
DISPLAY=paxbox1.paxco.com:1.1

depending on where you want your actual windows to appear and which input devices you want to use.

Ilya Kogan
  • 21,995
  • 15
  • 85
  • 141
paxdiablo
  • 854,327
  • 234
  • 1,573
  • 1,953
  • 1
    **Why do you need to have this `DISPLAY=paxbox1.paxco.com:0.0; export DISPLAY` in your profile?** --- Is the purpose of this code `DISPLAY=paxbox1.paxco.com:0.0 firefox &` to see many displays in Firefox? – Léo Léopold Hertz 준영 Aug 04 '09 at 00:20
  • (1) DISPLAY needs to be set *somewhere*. If it's always the same for you, do it in your profile. (2) This sets DISPLAY *only* for that single firefox command. – paxdiablo Aug 04 '09 at 00:43
  • What I tend to do is have DISPLAY set to ":0.0" in my profile (since that's the one I use 99% of the time. When I have a need to run a program on a different display I use "DISPLAY=elsewhere:0.0 firefox &". – paxdiablo Aug 04 '09 at 00:56
  • @paxdiablo at which line of `.profile` must we add `DISPLAY=paxbox1.paxco.com:0.0; export DISPLAY ` ? –  Jun 03 '14 at 09:15
  • @begueradj, anywhere in the file that runs. If the profile is a simple sequential set of commands, anywhere. If it's more complex, with conditionals, branches and so on, you'll have to figure out where based on the control flow. – paxdiablo Jun 03 '14 at 09:44
  • Is it normal to try to launch firefox on an a remote machine (Ubuntu Desktop) from a local one which is Ubuntu Server (no GUI) ? –  Jun 03 '14 at 09:52
  • 1
    @begueradj, yes, if the machine you're running on has no gui, it's normal to run a gui app on a macine thhat does, though not usually one remote from where you want to control it. – paxdiablo Jun 03 '14 at 10:55
  • 3
    One trick we used to play on colleagues who hadn't secured their X display server correctly was to used their IP address to open up `xeyes` on their screen (a pair of eyes that would look towards their mouse cursor) or, better yet, `xroach`, which would create a plethora of on-screen cockroaches which would quickly scurry behind windows when you uncovered them :-) – paxdiablo May 21 '15 at 04:48
  • 2
    For others coming here looking for clarification on the terms "monitor", "screen", "display", etc., this section of the Wikipedia article was useful: https://en.wikipedia.org/wiki/X_Window_System#Nomenclature – waldyrious Apr 15 '17 at 14:53
28
$ export DISPLAY=yourmachine.yourdomain.com:0.0
$ firefox &
Pablo Santa Cruz
  • 176,835
  • 32
  • 241
  • 292
  • 9
    Just to add a note, you can change the :0.0 to ":0.1" if you have a second monitor, etc. – Andy White Apr 24 '09 at 03:41
  • 5
    Likewise, if you have multiple X sessions running, you can use :1.0, :2.0, etc to start the application on a specific session. – James Apr 24 '09 at 03:56
20

When you are connecting to another machine over SSH, you can enable X-Forwarding in SSH, so that X windows are forwarded encrypted through the SSH tunnel back to your machine. You can enable X forwarding by appending -X to the ssh command line or setting ForwardX11 yes in your SSH config file.

To check if the X-Forwarding was set up successfully (the server might not allow it), just try if echo $DISPLAY outputs something like localhost:10.0.

TobiX
  • 936
  • 6
  • 17
16

login to your server via

ssh -X root@yourIP

edit /etc/ssh/sshd_config file, and add this line to it.

X11UseLocalhost no

Restart sshd. for CentOS (check your distribution)

/sbin/service sshd restart

check your DISPLAY

echo $DISPLAY

you should see this

yourIP:10.0

Enjoy

firefox

for more info

Ammar Bozorgvar
  • 1,230
  • 19
  • 30
  • 3
    Can you please explain why this line `X11UseLocalhost no`? – Léo Léopold Hertz 준영 Feb 17 '18 at 22:00
  • Thank you for the solution! Works perfectly for me. Ubuntu 18.04 – cavalcantelucas Oct 21 '19 at 02:26
  • @LéoLéopoldHertz준영 without this option X11 could redirect to the host machine or you - the client terminal. You can follow the more complex instructions to point X server at the client or use this setting to make unambiguous. – Craig.C Mar 19 '20 at 21:53
  • 1
    It may also work adding `X11Forwarding yes` **on the remote device**, that is the sshd server. The ssh client with -X option manages setting a suitable DISPLAY variable. – Ale Jun 24 '22 at 12:04
15

Try

export DISPLAY=localhost:0.0
Léo Léopold Hertz 준영
  • 134,464
  • 179
  • 445
  • 697
sreenath
  • 241
  • 2
  • 5
10

Please do NOT try to set $DISPLAY manually when connecting over SSH.
If you connect via SSH -X and $DISPLAY stays empty, this usually means that no encrypted channel could be established.

Most likely you are missing the package xauth or xorg-x11-xauth. Try to install it on the remote machine using:

sudo apt-get install xauth

or

sudo apt-get install xorg-x11-xauth

After that end and restart your SSH connection. Don't forget to use SSH -X so that X Window output is forwarded to your local machine.

Now try echo $DISPLAYagain to see if $DISPLAY has been set automatically by the SSH demon. It should show you a line with an IP address and a port.

Jpsy
  • 20,077
  • 7
  • 118
  • 115
8

I ran into a similar issue, so maybe this answer will help someone.

The reason for the Error: no display specified error is that Firefox is being launched, but there is no X server (GUI) running on the remote host. You can use X11 forwarding to run Firefox on the remote host, but display it on your local host. On Mac OS X, you will need to download XQuartz in order to use X11 forwarding. Without it, you won't have a $DISPLAY variable set, so if you try and echo $DISPLAY, it will be blank.

Andrew
  • 227,796
  • 193
  • 515
  • 708
6

Try installing the xorg-x11-xauth package.

Narendra Pathai
  • 41,187
  • 18
  • 82
  • 120
thegriglat
  • 61
  • 1
  • 2
  • 1
    it must be installed on the remote or the local machine ? –  Jun 03 '14 at 09:19
  • 3
    It must be installed on the machine you are connecting to, NOT on the machine on which you want to see the X11-Gui. – kiltek Dec 01 '15 at 07:23
6

I faced similar problem today. So, here's a simple solution: While doing SSH to the machine, just add Ctrl - Y.

ssh user@ip_address -Y

After login, type firefox &. And you are good to go.

Léo Léopold Hertz 준영
  • 134,464
  • 179
  • 445
  • 697
1

Even i faced the same in CentOS 6.8.

yum reinstall xorg*

End your current session and open another session in tool like mobiXterm. Make sure session has X11 forwarding enabled in the tool.

Srihari Karanth
  • 2,067
  • 2
  • 24
  • 34
0

I through vnc to understand the X11 more. To specify the display to get a many-displayed program, export DISPLAY=IP:DisplayNum.ScreenNum

For example,

vncserver :2
vncserver -list
echo '$DISPLAY'=$DISPLAY 
export DISPLAY=:2  # export DISPLAY=IP:DisplayNum or export DISPLAY=:DisplayNum for localhost; So that can vnc connect and see the vnc desktop :2 if $DISPLAY is not :2.
echo '$DISPLAY'=$DISPLAY
Yang
  • 51
  • 6
-1

I'm using xming server before typing firefox use the following command export DISPLAY=0:0