4

If I ssh into a machine, I can run graphical applications if I enable X11 forwarding - I run gedit from the command line, and gedit pops up as a window. My question is this: Is there a way to make a window pop up for applications that are already running?

Example: Suppose I have two machines, A and B. I open gedit on A, and type some text and leave. Then I ssh into A from B. If I run gedit I'll just spawn another process. Can I access the gedit process that's already running (with some text)? Or is this a job for vnc?

  • The problem is that once applications have opened a connection to anX server, you can't redirect that connection. So you have to introduce a means of redirection beforehand, e.g. with xpra, see answer below. – dirkt Nov 1 '17 at 22:24
6

Not really a solution to literal "grabbing windows of programs already running", but still…

Use xpra.

On X11, it is also known as screen for X11: it allows you to run programs, usually on a remote host, direct their display to your local machine, and then to disconnect from these programs and reconnect from the same or another machine, without losing any state.

[…]

Xpra also allows forwarding of sound, clipboard and printing services. Sessions can be accessed over SSH, or password protected over plain TCP sockets with or without SSL.

It has to be installed, configured and started beforehand, just like screen or tmux for console applications. You have to run your program via xpra in the first place, then you can do the magic of (re)connecting from different machines.

xpra is available as xpra package at least in Debian and Ubuntu. I have used it few times. The performance was better than for plain X forwarding.

Examples are here. The following are from man xpra on my Kubuntu:

xpra start :7

Start an xpra server using display number :7.

DISPLAY=:7 firefox

Start firefox running inside the xpra server. Run this on the host where xpra was started or in terminal forwarded by xpra. No window will appear until you attach with xpra attach.

You run the above examples on your A. Then you can attach directly from A:

xpra attach :7

Attach to the xpra server that is using local display number :7. Any apps running on that server will appear on your screen.

or from your B:

xpra attach ssh:foo@frodo:7

Use ssh to attach to the xpra server that is running on machine frodo as user foo and using display :7. Any apps running on that server will appear on your local screen.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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