Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

Once upon a time,

DISPLAY=:0.0 totem /path/to/movie.avi

after ssh 'ing into my desktop from my laptop would cause totem to play movie.avi on my desktop.

Now it gives the error:

No protocol specified
Cannot open display:

I reinstalled Debian squeeze when it went stable on both computers, and I guess I broke the config.

I've googled on this, and cannot for the life of me figure out what I'm supposed to be doing.

(VLC has an HTTP interface that works, but it isn't as convenient as ssh.)

share|improve this question
1  
Does your remote machine show a .Xauthority file? The other obvious question is - are your ssh server and client configured to allow X forwarding? What command did you use to ssh? –  Faheem Mitha Mar 25 '11 at 21:35
    
am I trying to forward X? I want the command to be executed on the host, not the client. My ssh command is just ssh me@host locate .Xauthority on the host computer doesnt match any files. –  justin cress Mar 25 '11 at 21:42
    
As Faheem suggests, there's a good change that your problem is due to totem not finding your X cookie, and you need to set XAUTHORITY to the proper value, i.e., the value in your regular session on your desktop. Read Linux: wmctrl cannot open display when session initiated via ssh+screen for some background; also see the related answer As root can I launch a graphical program on another users desktop?. –  Gilles Mar 25 '11 at 21:49
    
@justin: yes, the command is executed on your desktop, but does the totem window appear on your laptop? If so, that is X fowarding. If you are doing that, I wonder how you are handing the sound. And why are you setting DISPLAY manually? That is not usually done. The Xauthority file would be located at ~/.Xauthority on any machine. –  Faheem Mitha Mar 25 '11 at 21:51
1  
alright, physically sitting at the computer and typing echo $XAUTHORITY gives /var/run/gdm3/auth-for-jcress-bb32gX/database in the ssh session, typing echo $DISPLAY = (the path above) does not resolve the problem –  justin cress Mar 25 '11 at 22:20

4 Answers 4

up vote 32 down vote accepted

(Adapted from Linux: wmctrl cannot open display when session initiated via ssh+screen)

DISPLAY and AUTHORITY

An X program needs two pieces of information in order to connect to an X display.

  • It needs the address of the display, which is typically :0 when you're logged in locally or :10, :11, etc. when you're logged in remotely (but the number can change depending on how many X connections are active). The address of the display is normally indicated in the DISPLAY environment variable.

  • It needs the password for the display. X display passwords are called magic cookies. Magic cookies are not specified directly: they are always stored in X authority files, which are a collection of records of the form “display :42 has cookie 123456”. The X authority file is normally indicated in the XAUTHORITY environment variable. If $XAUTHORITY is not set, programs use ~/.Xauthority.

You're trying to act on the windows that are displayed on your desktop. If you're the only person using your desktop machine, it's very likely that the display name is :0. Finding the location of the X authority file is harder, because with gdm as set up under Debian squeeze or Ubuntu 10.04, it's in a file with a randomly generated name. (You had no problem before because earlier versions of gdm used the default setting, i.e. cookies stored in ~/.Xauthority.)

Getting the values of the variables

Here are a few ways to obtain the values of DISPLAY and XAUTHORITY:

  • You can systematically start a screen session from your desktop, perhaps automatically in your login scripts (from ~/.profile; but do it only if logging in under X: test if DISPLAY is set to a value beginning with : (that should cover all the cases you're likely to encounter)). In ~/.profile:

    case $DISPLAY in
      :*) screen -S local -d -m;;
    esac
    

    Then, in the ssh session:

    screen -d -r local
    
  • You could also save the values of DISPLAY and XAUTHORITY in a file and recall the values. In ~/.profile:

    case $DISPLAY in
      :*) export | grep -E ' (DISPLAY|XAUTHORITY)=' >~/.local-display-coordinates.sh;;
    esac
    

    In the ssh session:

    . ~/.local-display-coordinates.sh
    screen
    
  • You could detect the values of DISPLAY and XAUTHORITY from a running process. This is harder to automate. You have to figure out the PID of a process that's connected to the display you want to work on, then get the environment variables from /proc/$pid/environ (eval export $(</proc/$pid/environ tr \\0 \\n | grep -E '^(DISPLAY|XAUTHORITY)=')¹).

Copying the cookies

Another approach (following a suggestion by Arrowmaster) is to not try to obtain the value of $XAUTHORITY in the ssh session, but instead to make the X session copy its cookies into ~/.Xauthority. Since the cookies are generated each time you log in, it's not a problem if you keep stale values in ~/.Xauthority.

There can be a security issue if your home directory is accessible over NFS or other network file system that allows remote administrators to view its contents. They'd still need to connect to your machine somehow, unless you've enabled X TCP connections (Debian has them off by default). So for most people, this either does not apply (no NFS) or is not a problem (no X TCP connections).

To copy cookies when you log into your desktop X session, add the following lines to ~/.xprofile or ~/.profile (or some other script that is read when you log in):

case $DISPLAY:$XAUTHORITY in
  :*:?*)
    # DISPLAY is set and points to a local display, and XAUTHORITY is
    # set, so merge the contents of `$XAUTHORITY` into ~/.Xauthority.
    XAUTHORITY=~/.Xauthority xauth merge "$XAUTHORITY";;
esac

¹ In principle this lacks proper quoting, but in this specific instance $DISPLAY and $XAUTHORITY won't contain any shell metacharacter.

share|improve this answer
2  
One way to automate this would be to create a ~/.xprofile which should only be run during the the X login and have it create/update ~/.Xauthority with the correct info. Would a symbolic link be enough? –  Arrowmaster Mar 25 '11 at 23:16
    
@Arrowmaster: That's a good suggestion. I hadn't thought of it. It won't work in all cases, for example if you log into more than one X session (on different terminals, with vnc, …), but it's simple, and it's good enough for typical use. A symbolic link is the best way. Hmm, actually there's a better, simple way: you can copy the information into ~/.Xauthority. –  Gilles Mar 25 '11 at 23:21
    
Would putting something like xauth extract - $DISPLAY | xauth -f "$HOME/.Xauthority" merge - in ~/.xprofile solve the case of multiple $DISPLAY's? –  Arrowmaster Mar 25 '11 at 23:52
    
@Arrowmaster: What problem do you see with multiple displays? While your code may be a little cleaner in principle since you're only extracting information about the display you're interested in, I don't see anything wrong with a simple merge in the asker's case, or indeed outside very unusual circumstances. –  Gilles Mar 25 '11 at 23:58
    
I came up with that before I noticed your edit. I based it mostly on the xauth man page example for merging across hosts with ssh. In this case I'm guessing the $XAUTHORITY created by GDM3 will only contain a single entry so your method with a single xauth call seem simpler. –  Arrowmaster Mar 26 '11 at 0:07

I solved this issue by adding

xhost +si:localuser:$USER

to ~/.xprofile. I don't know if this is altogether secure (I'd be very interested to hear what more knowledgeable folk think), but I'm guessing that it's a lot better than turning off access control (with xhost +) as is commonly suggested when you google for this issue.

share|improve this answer
    
localuser server-interpreted addresses are completely secure. Debian even does this by default as part of the login process (in /etc/X11/Xsession.d/35x11-common_xhost-local). See the Xsecurity man page for more details. –  Sam Morris May 31 '13 at 22:31

You need to export DISPLAY=:0.0

share|improve this answer

You don't want that $ on the front of DISPLAY=:0.0. That said, what's the error message?

share|improve this answer
    
sorry, $ is just the prompt, i dont type it. –  justin cress Mar 25 '11 at 21:27

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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