7

Is there a way to run a Gui application (X11) in background so that if I disconnect, I can resume the running app again?

I am using SmarTTY on windows to connect to remote CentOS. When I run a Gui application (e.g. gnome-help) it starts Xming server and displays its window.

I want to keep it running even if I disconnect, crash or close ssh connection. So that I can get back to running applicaition later.

I have tried 'screen' and '&' and combination of both but neither works. I can not connect again to the GUI application when SSH connection is closed.

--EDIT--

As answered by Anthon

  1. Install both the VNC Server and VNC Viewer on the remote system (e.g. CentOS).
  2. Start VNC Server on remote Xvnc -localhost :13
  3. Start VNC Viewer so that it displays locally via X (e.g. on your Windows)
  4. Set display export DISPLAY=:13
  5. Start a GUI application and it will be displayed in the VNC Viewer
LifeH2O
  • 204

1 Answers1

4

The X application needs a screen to connect to and normally (if you connect via ssh using -X that is your local screen). What you can do instead is use Xvnc and create a virtual screen for you X application to connect to and then, after logging back in, use a vncviewer to observe what is happening on this virtual screen. This functions in a similar way as using screen or tmux for terminal sessions.

You start Xvnc via:

  Xvnc -localhost -SecurityTypes=None :13

with 13 being a unique number. You use this number to set your DISPLAY environment variable before starting the X application.

During startup Xvnc will tell you which port to use to connect (5913 in my case). If you do not specify -localhost you can connect over the network directly using a vnc viewer without first having to login using ssh (this depends on your firewall of course, and you should use password protected connections instead of -SecurityTypes=None)

On Debian based systems you can install Xvnc from the package vnc4server

Anthon
  • 79,293
  • I can only connect with SSH port (22). I am not sure how many other ports are open, because many are blocked by institute. – LifeH2O Dec 18 '14 at 11:58
  • Then just use -localhost and first ssh into the machine. xvncviewer can display via X as well ;-) – Anthon Dec 18 '14 at 12:06
  • I have installed Xvnc (TigerVNC) by following instructions from http://www.krizna.com/centos/install-vnc-on-centos-6/ On my Windows client I have installed UltraVNC Viewer. Default port 5900 for VNC is probably blocked. Also it does not allow me to use port 22 to connect with remote machine with UltraVNC as remote::22 – LifeH2O Dec 18 '14 at 12:28
  • @LifeH2O as I already wrote just ssh into the machine as usual and use xvncviewer to connect to th Xvnc instance. – Anthon Dec 18 '14 at 12:29
  • From the duplicate question I found that I have to tunnel through SSH connection to connect to VNC server. There is no xvnc4viewer for CentOS. I am trying to connect CentOS from windows machine and all ports but SSH are blocked. Sorry, can not understand what you are suggesting. – LifeH2O Dec 18 '14 at 13:29
  • -localhost: Only allow connections from the same machine. Useful if you use SSH and want to stop non-SSH connections from any other hosts. See the guide to using VNC with SSH. – LifeH2O Dec 18 '14 at 13:33
  • @LifeH2O you don't have to tunnel through ssh, I am not sure why you make your life more complicated than necessary. You can just login with ssh as usual and start any vnc viewer you have on CentOS to connect to the Xvnc run locally on the server. The VNC viewer will display via X on your client system (from where you started ssh). That is exactly where -localhost comes into play: connect to the local machine, once you ssh-ed into it, your server is your local machine for vnc viewer. – Anthon Dec 18 '14 at 13:51
  • 1
    Now I understand your point. That must work great. Start a VNC Viewer on remote system and display it locally on client via X (Xming etc). That is a great idea. – LifeH2O Dec 18 '14 at 14:17
  • Now VNC is showing only a blank black screen. Usually when i start gnome-session it displays via X locally. How do I start it on remote so that I can see it in VNCViewer. – LifeH2O Dec 18 '14 at 14:32
  • Have you started your application with the appropriate DISPLAY environment variable? (see answer). The application needs to know where to display if not to the default screen. – Anthon Dec 18 '14 at 14:34
  • I can run individual apps in background and view them in VNC but gnome-panel or gnome-session close when connection closes. – LifeH2O Dec 18 '14 at 15:19
  • @LifeH2O My only guess is that those are not well behaving X applications – Anthon Dec 18 '14 at 15:31