Run a GUI application in background and reconnect later

10,275

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

Share:
10,275

Related videos on Youtube

dhdhagar
Author by

dhdhagar

Updated on September 18, 2022

Comments

  • dhdhagar
    dhdhagar over 1 year

    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
    • Admin
      Admin over 9 years
      Screen for X sounds like what you want.
  • Anthon
    Anthon over 9 years
    Then just use -localhost and first ssh into the machine. xvncviewer can display via X as well ;-)
  • dhdhagar
    dhdhagar over 9 years
    I have installed Xvnc (TigerVNC) by following instructions from 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
  • Anthon
    Anthon over 9 years
    @LifeH2O as I already wrote just ssh into the machine as usual and use xvncviewer to connect to th Xvnc instance.
  • dhdhagar
    dhdhagar over 9 years
    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.
  • dhdhagar
    dhdhagar over 9 years
    -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.
  • Anthon
    Anthon over 9 years
    @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.
  • dhdhagar
    dhdhagar over 9 years
    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.
  • dhdhagar
    dhdhagar over 9 years
    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.
  • Anthon
    Anthon over 9 years
    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.
  • dhdhagar
    dhdhagar over 9 years
    I can run individual apps in background and view them in VNC but gnome-panel or gnome-session close when connection closes.
  • Anthon
    Anthon over 9 years
    @LifeH2O My only guess is that those are not well behaving X applications