Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I want to run a GUI application on a remote machine I only have ssh access to. I don't need to, or want to, see the GUI window. (I know I could use something like ssh -C -X remote_server if I wanted the GUI to be on my client.)

I know X is running on the remote machine, as ps shows this:

root  ... /usr/bin/Xorg :0 -br -audit 0 -auth /var/gdm/:0.Xauth -nolisten tcp vt7

I set DISPLAY=:0.0 but I then get "Xlib: connection to ":0.0" refused by server" when I try to use it.

At Get remote x display working in linux without ssh tunneling and Xserver doesn't work unless DISPLAY=0.0 I see the advice to use gdmsetup to allow X to listen on TCP. But, gdmsetup is a GUI application! And trying to run it over ssh -X did not work ("X11 connection rejected because of wrong authentication").

So, is there a text file I can edit to remove -nolisten? And, after editing it, how do I safely restart X, remotely? (There is other stuff running on this machine, so requesting a reboot is possible, but undesirable.) If not, should gdmsetup be able to run over ssh and I should persevere in that direction?

UPDATE: I had to do the ssh -X session as root (ssh as a normal user, then sudo or su, does not work.) So, I did the edit with gdmsetup. I then restarted X with gdm-restart. I've also done xhost + from that ssh -X session. The ps line no longer shows the -nolisten tcp part. But still no luck connecting to it, with either DISPLAY=:0 or DISPLAY=localhost:0

UPDATE#2: I just noticed the reason xauth + hadn't helped (when done over ssh -X) was it altered my client machine, not the remote server! Oops. Good job I was inside the firewall! (I think the reason it had done this was related to the XAUTHORITY environmental variable, see Cougar's reply.)

share|improve this question
    
Is the remote machine secure - could you just run xhost + to allow any user to access the X display, would that be enough? If so then xhost + as the user that started X and the export DISPLAY=:0 on the remote machine should be enough to direct output to the remote X and save you having to see it –  Paul Nov 22 '11 at 4:11
    
Thanks @Paul As root (over ssh) I did xhost + but got xhost: unable to open display "". I then tried export DISPLAY=:0.0 and tried again and instead got Xlib: connection to ":0.0" refused by server, Xlib: No protocol specified and xhost: unable to open display ":0.0" –  Darren Cook Nov 22 '11 at 8:04
    
While the X server is owned by root, it almost certainly didn't start it, it runs as suid root. One of the normal user account would have started X and that is the account you need to do the xhost + from –  Paul Nov 22 '11 at 8:26
    
Thanks @Paul. Perhaps restarting gdm as root was enough to allow xhost + to run now. But it still hasn't helped (see my UPDATE above). –  Darren Cook Nov 22 '11 at 8:40
add comment

3 Answers 3

up vote 2 down vote accepted

as it seems you want your app to attach to the session root owns right now: the gdm - login screen.

why don't you just launch your own xserver and your program:

%> startx /your/program -- :1

(Added by Darren) Here is precisely what I did. In one ssh session, become root, and type:

startx -- :1 &
export DISPLAY=:1
xhost + &

Then in another ssh session, normal user:

export DISPLAY=:1
xclock

(Just using xclock as a test.)

share|improve this answer
    
Thanks @akira. I couldn't startx as a normal user, and didn't want to run my app as root, so used two windows. Editing your answer seemed the best place to describe how I did that; I hope you don't mind :-) –  Darren Cook Nov 22 '11 at 9:27
    
@Darren Approved — I think that's fine, always good to have a practical example. –  slhck Nov 22 '11 at 9:40
    
if you can't launch startx as a normal user (ubuntu? debian?) then just cnfigure your system to let you launch startx as a normal user. –  akira Nov 22 '11 at 11:48
add comment

If you just need to connect to the remotely running X display and start your program then it is just an authorization problem you have. Now it depends how the authorization is set up.

One way is to use xhost and give permissions per IP but this is highly unsecure because any programm running on this machine (or any machine if you just use +) can automatically connect with your X dislpay server.

The common way is to use X authority file. Then you just need to know this file and have an access to it. Now it depends on distribution if this file is .Xauthority in your home directory or is it some temporary file set up every time you start X session.

In first case everything works out of box, in latter case you need to know this temporary file name. One way to find it out is to look at XAUTHORITY variable in environment of some program (like windowmanager) already running under your X server. You can get environment variables easily from /proc/PID/environ file like this:

cat /proc/12345/environ | xargs -0 -L 1 echo | grep XAUTHORITY

Then just export XAUTHORITY and DISPLAY variables to your shell and start your program

share|improve this answer
    
Thanks @Cougar, that worked. I found centos keeps that file in /var/gdm. As a normal user exporting XAUTHORITY was no help. So, what I actually did was, as root, export DISPLAY=:0;export XAUTHORITY=/var/gdm/:0.Xauth then I was able to run xhost +. After doing that I was able to login as a normal user, just do export DISPLAY=:0 and now I can run X apps! –  Darren Cook Nov 23 '11 at 1:38
    
P.S. xhost + was just for quick testing. xhost 127.0.0.1 is more sensible, and still works. –  Darren Cook Nov 23 '11 at 1:46
    
Why do you need xhost if you can provide XAUTHORITY directly to your app? ;-) –  Cougar Nov 23 '11 at 14:17
    
Not sure about the smiley, but if that was a serious question my understanding is export XAUTHORITY told root where to find the file that xhost will modify. –  Darren Cook Nov 23 '11 at 23:38
    
The problem with xhost is that it gives access to all programs coming from that IP address. You do not need to open access with xhost if you already know XAUTHORITY. xhost can be used in very closed and controlled environment but even then I would try to avoid it. –  Cougar Nov 24 '11 at 8:34
show 2 more comments

It looks like you are going to a great length to make it work. As an alternative, I could recommend installing FreeNX on the remote machine and access it with NXClient. You will get a full remote desktop via ssh and you will be able just open terminal window and run your app. This will take less time then trying to figure out the tunneling with ssh.

share|improve this answer
    
Thanks @dtoubelis. That is an interesting answer for a different question (I think VNC is also used for this?); also ssh tunneling works fine. The question here was how to start an app over ssh when that app insists on wanting to show a window (even though I don't want or need to see its window). export DISPLAY=:0 was the simple answer to that; everything else here was working around the security! –  Darren Cook Nov 23 '11 at 23:34
    
@Darren Cook: I was not trying to answer your question in itself but rather to offer an alternative solution to your problem. I personally find ssh tunneling to cumbersome and I usually opt for simpler solutions. And, yes VNC is another alternative but it is not nearly as good as FreeNX. –  dtoubelis Nov 24 '11 at 1:19
add comment

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.