Run a GUI application in background and reconnect later
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
Related videos on Youtube
dhdhagar
Updated on September 18, 2022Comments
-
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
- Install both the VNC Server and VNC Viewer on the remote system (e.g. CentOS).
- Start VNC Server on remote
Xvnc -localhost :13
- Start VNC Viewer so that it displays locally via X (e.g. on your Windows)
- Set display
export DISPLAY=:13
- Start a GUI application and it will be displayed in the VNC Viewer
-
Admin over 9 yearsScreen for X sounds like what you want.
-
Anthon over 9 yearsThen just use
-localhost
and firstssh
into the machine.xvncviewer
can display via X as well ;-) -
dhdhagar over 9 yearsI 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 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 over 9 yearsFrom 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 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 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 withssh
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 over 9 yearsNow 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 over 9 yearsNow 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 over 9 yearsHave 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 over 9 yearsI can run individual apps in background and view them in VNC but
gnome-panel
orgnome-session
close when connection closes. -
Anthon over 9 years@LifeH2O My only guess is that those are not well behaving X applications