How to start a GUI software on a remote Linux PC via SSH
Sometimes I need to start XMBC media player or other GUI software a one of my PC (small Xubuntu PC used as a media center).
Usually I do this starting a X11vnc server on the remote PC via SSH and than connecting with an Xvnc client to the Xfce desktop.
Is there a way 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:
[email protected]:~$ ssh tim [email protected]:~$ export DISPLAY=:0 [email protected]:~$ firefox
Firefox is now running on
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"
It said `No DISPLAY: this may not be what you want.` when i tried it (I tried it from abiword by the way. `
@PyRulez Note the "or whatever the remote display is numbered as" in the first line. If it's not the first graphical server it might be :1 or higher. Run `w` to see who's logged in and where. That will tell you the DISPLAY number too.
I do have a display 0, and it is the only display and it is physically on and working.
I have turned it on and everything I do opens on my computer's screen. I want it to go back to normal and stop doing it, without opening a new shell
sometimes you want to do the opposite and run the X app locally just connect using -Y and then run your app `ssh -Y `
I have only mouse and starting the keyboard remotely from the command line is reaaaally helpful! :) `ssh [email protected] "DISPLAY=:0 nohup onboard"`
Tried ssh-ing into macOS (Sierra) laptop from my linux box, works exactly as expected. Can get `mpv` to play a video file on my mac laptop AND it passes along the keyboard shortcuts as well if the term session is the active window. This is damned awesome, thank you!
I just get `No protocol specified Unable to init server: Could not connect: Connection refused Error: cannot open display: :0` when trying to use this.
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
-Yoption and the run the application (e.g. firefox):
ssh -Y ... firefox
-Ydoesn'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 [email protected] DISPLAY=:0 nohup firefox
To display the application nowhere
You need to install & start xvfb. xvfb will create an invisible X session at
DISPLAY10. Then you start your application directing its output to that
sudo apt install xvfb sudo Xvfb :10 -ac -screen 0 1024x768x24 & DISPLAY=:10 firefox