How to start a GUI software on a remote Linux PC via SSH

Yes. You just need to run export DISPLAY=:0 (or whatever the remote display is numbered as) in your ssh session and programs run will run on the remote display. A quick example:

oli@bert:~$ ssh tim
oli@tim:~$ export DISPLAY=:0
oli@tim:~$ firefox

Firefox is now running on tim's display.

However when you close your ssh session, most of the time the remote application will close. If you want to disconnect from ssh but leave the application running you need to launch it in a special way using something like screen (keeps the ssh session running in the background) or nohup, or another method. For more information on this there was recently another question on it.

You can shorten this all down into one command that will connect, export the display in-line and start the application in a way that won't close it after the ssh session dies:

ssh tim "DISPLAY=:0 nohup firefox"

Depends on where you want to see the application displayed

To display the application on your local PC

You first ssh to the remote computer with the additional -Y option and the run the application (e.g. firefox):

ssh -Y ...
firefox

If -Y doesn't work check you sshd config on the remote PC (see Denis Lukinykh's answer). Another similar option is -X. Google for the differences.

To display the application on an existing session at the remote PC

You need to login with user A at the remote PC and leave the session open. Afterwards you can ssh with the same user A and start the application (e.g. firefox) like this:

ssh A@...
DISPLAY=:0 nohup firefox

To display the application nowhere

You need to install & start xvfb. xvfb will create an invisible X session at DISPLAY 10. Then you start your application directing its output to that DISPLAY:

sudo apt install xvfb
sudo Xvfb :10 -ac -screen 0 1024x768x24 &
DISPLAY=:10 firefox

Tags:

Ssh

Gui