remotely controlling the screen from gdm under linux

I have a remote box.
The only way I know of to get it to display is to sit in front of it, log in.
Then I type

xhost myhostid

to allow myself to display to it.
Then I remote ssh to it, set display:

export DISPLAY=:0.0

and run my graphical code.

I would prefer to log into the box (as root if necessary) and force the machine to recognize me as the one logged into the console. What do I do to make this happen?
When I log into the box from the console, even if I am remote, it doesn't recognize my authority, because the direction is reverse -- my login has been granted permission to display on my remote screen, not on the box I'm on.
LVL 11
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Dushan De SilvaTechnology ArchitectCommented:
You can try with VNC server.
type on command line "vncserver"
If it not installed, you can install it from installation CD and can configure. If need more details don't hesitate to ask from me.

BR Dushan
dbkrugerAuthor Commented:
You misunderstood me, and have the wrong direction.
I am sitting at computer A.
I remote login to computer B.

by default, my ssh already automatically can display a window from a job running on B to A.
But I want to run on B, and display on its screen, which is asleep.
I have already asked and found out how to wake up a monitor under X, and that works.

My question is, how do I simulate logging into remote machine B from the console, so that I have the right to display to its screen?
> .. and force the machine to recognize me as the one logged into the console.
only if there is a VNC running or with a hardware switch (KVM)
Cloud Class® Course: Microsoft Exchange Server

The MCTS: Microsoft Exchange Server 2010 certification validates your skills in supporting the maintenance and administration of the Exchange servers in an enterprise environment. Learn everything you need to know with this course.

dbkrugerAuthor Commented:
I frankly don't believe this is not possible with stock X11, and by definition it cannot be impossible with a little programming, which is why I posted to this area.
Look, if I wrote a script that did an init 3, did my own startx, then I would be in control and could presumably pass my .Xauthority to whom I like. But clearly gdm does something like that, and so I can't believe it's not doable, it's just that I don't know how to do it.

I still don't see what vncserver has to do with it, as I don't want to display remotely at all. I want a program running on B to display on B, I just want to log in remotely to start that process. Suppose I did start vncserver running on the machine. So what? How is an X application on that machine going to draw to itself?

> I just want to log in remotely to start that process.
log in and start xterm (or whatever application you want) with display to your local machine
dbkrugerAuthor Commented:
ahoffman, I'm not sure if you mean the following, but it does not work.

I am on machine A.
In another room, far away, is a machine B.
I want to run a program on machine B and display the results on the screen in that room to whoever is there. I do not want to run on A and display to B, or run on B and display to A. The only thing I want distributed is the ability to reach out, run something on the remote box that shows up on its screen.

ssh B
export DISPLAY=:0.0

The xterm fails, because I have no right to write to B's screen, even though I am the only one logged in. This is true even if I'm root.
B is running gdm.
If I log into the console, then even though the same user is remotely logged in and logged in at the console, the remote user is stlil not able to write. I need either an xauthority or xhost permission.

xhost B

works, but that requires me to keep machine B logged in at all times with permission to receive drawing from itself.

I could take the machine to runlevel 3:

init 3
and then I would have the right, but I was looking for a more elegant way, perhaps I can set up some xauthority so that when no one is logged in, I can draw on the screen?

Is there some .Xauthority file that exists when no one is logged in?
If not, can one be configured?
> .. run something on the remote box that shows up on its screen.

prompt on B% nohup xterm -display IP-or-FQDN-of-B:0 &

> The xterm fails, because I have no right to write to B's screen,
X for root is disabled in most modern distributions, unfortunatelly there're different corresponding config file where to find it, best you check in /etc/; some files are login.defs default/login sysconf/login etc.
Duncan RoeSoftware DeveloperCommented:
How did X get started on B? What is the X authentication in use? Assuming it's Xauth, you have to know where the authority file is. This is easy if you boot the system to a non-X level, login in to a console and type startx to get X started: in that case the .Xauthority will be in your home directory. You can telnet in as that same user, set your DISPLAY to :0.0, and you'll be in business.
If logging in via xdm it's a little more complex IIRC. .Xauthority is *not* in your home directory - rather its location is given by the environment variable XAUTHORITY. You should be able to see this from an xterm when at the console: try typing "env|grep AUTH".
This $XAUTHORITY location is what you need to know when telnetting in. I haven't used xdm for a while so can't remember - if $XAUTHORITY is some kind of dynamic-looking filename then you'll need to record it somewhere for the benefit of remotes - maybe something in your .bashrc like:
  env|grep XAUTHORITY >/dev/null && env|grep XAUTHORITY >/tmp/my_auth
That way the file gets written by bash shells that have the variable and left alone by those that haven't. Now your remote login can use the contents of that file to set up its own .XAUTHORITY
Duncan RoeSoftware DeveloperCommented:
Oops - I mean set up its own XAUTHORITY environment var. Of course if the filename looks like it's constant then just set XAUTHORITY to that

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Duncan RoeSoftware DeveloperCommented:
Oh you're using gdm - should be much the same as xdm as far as authentication goes. You might get lucky with "locate Xauthority"
dbkrugerAuthor Commented:

our cluster is down for the holidays, due to (as usual) our air conditioning, but as soon as they fix it, and I can fire up the machines again, I'll check. This sounds like a winner.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Linux OS Dev

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.