36

I use GNU Screen constantly. But, I've been trying to figure out if there is someway to get X11 apps to forward over screen when I am ssh-ing (Is that a word?). Currently if I try to run 'gedit' through screen, it opens on my 'server' computer and not on my client. If I do the same outside of screen, then everything is fine. But I want everything to be fine when I use screen too!

Thanks!

PS: I have googled the problem and I see mention of xmove, but I can't seem to find the package that contains xmove on my ubuntu. (ubuntu 10.10)

Kees Cook
  • 17,823
Sandro
  • 577

7 Answers7

35

To manually do this, once you have SSHed in, but before you reattach to screen, check your DISPLAY environment variable:

echo $DISPLAY

Once you have re-attached to screen, explicitly set the environment variable:

export DISPLAY=:N.0

where :N.0 is what the echo showed before the attach. This won't be perfect, since some application may be expecting to talk to the Session D-Bus, which is a bit more complex to send over the SSH connection.

Kees Cook
  • 17,823
14

there's a program called xpra in the repositories, it's like gnu screen for x11. it's not too hard to work with:

X Persistent Remote Applications

Xpra gives you the functionality of GNU Screen for X applications.

It allows the user to view remote X applications on their local machine, and disconnect and reconnect from the remote machine without losing the state of the running applications.

Avihay
  • 141
6

Byobu automatically reattaches ssh and gpg agents. I could make it reattach the display variable to, if that's helpful to you...

2

This is how I got it working when running byobu

Add this line in .bash_login before the "_byobu_source.." line:

echo $DISPLAY > $HOME/.display.env

And then add this line to .bashrc:

if [ ! -z ${SSH_CONNECTION+x} ]; then
  export DISPLAY=$(cat $HOME/.display.env) 
fi
harre
  • 31
1

It seems that the problem is that the environment variable XAUTHORITY is not preserved in the screen session. I solved this by adding the following to my .bashrc. I didn't think this should be necessary but I guess you do what you must:

# ensure X forwarding is setup correctly, even for screen
XAUTH=~/.Xauthority
if [[ ! -e "${XAUTH}" ]]; then
 # create new ~/.Xauthority file
 xauth
fi
if [[ -z "${XAUTHORITY}" ]]; then
 # export env var if not already available.
 export XAUTHORITY="${XAUTH}" 
fi

I don't expect this to be the best solution, or the most concise, but it works.

Mark
  • 111
0

FreeNX is a wonderful app for working with remote displays.

Habitual
  • 254
0

Based on @harre suggestion, I found this to be the best working solution, at least for RHEL via Putty. I know there's a better way than to create a file that holds the var, but this works out of the gate to get X11 to have access to the DISPLAY when loaded via gnu screen.

Automated Solution

Add to .bashrc (or .bash_profile, depending on your use case)

#.bashrc
if [ -f ~/etc/.bash-screen-x11 ]; then
   echo $DISPLAY > $HOME/.display.env
   source ~/etc/.bash-screen-x11
fi

Then add the following file(or your path choice)

#~/etc/.bash-screen-x11
# sets back display var.
if [ -z $STY ]; then
  export DISPLAY=$(cat $HOME/.display.env)
fi