How to start X application from SSH
Solution 1
If you don't care to see what the application is doing, you can supply it with a "virtual" x server with xvfb:
Xvfb provides an X server that can run on machines with no display hardware and no physical input devices. It emulates a dumb framebuffer using virtual memory. The primary use of this server was intended to be server testing, but other novel uses for it have been found, including testing clients against unusual depths and screen configurations, doing batch processing with Xvfb as a background rendering engine, load testing, as an aid to porting the X server to a new platform, and providing an unobtrusive way to run applications that don't really need an X server but insist on having one anyway.
After installing it, you can start it with:
sudo Xvfb :10 -ac -screen 0 1024x768x24 &
it'll run in the background, then you start your clients with:
DISPLAY=:10 your-client
Solution 2
A short command:
ssh -X <username>@<host> gedit &
from man ssh
-X Enables X11 forwarding.
This can also be specified on a per-host basis in a configuration file.
X11 forwarding should be enabled with caution. Users with the
ability to bypass file permissions on the remote host (for the
user's X authorization database) can access the local X11
display through the forwarded connection. An attacker may then
be able to perform activities such as keystroke monitoring.
Check
/etc/ssh/sshd_config
on the server side:sudo nano /etc/ssh/sshd_config
for the lines below:
X11Forwarding yes X11UseLocalhost no
Restart the ssh srever, if you have made changes:
sudo service ssh restart
Check
/etc/ssh/ssh_config
on the client side:sudo nano /etc/ssh/ssh_config
for the lines below
ForwardX11 yes ForwardX11Trusted yes
Solution 3
You just need to run export DISPLAY=:id# in your ssh session and programs run will run on the remote display. A quick example:
maythux@maythuxPC:~$ ssh testSSH@myServer
maythux@maythuxPC:~$ export DISPLAY=:0
maythux@maythuxPC:~$ gedit
Now gedit
will run on the user named testSSH display
You can shorten this all down into single command:
ssh testSSH@myServer "DISPLAY=:0 nohup gedit"
Related videos on Youtube
Paweł Wojtal
Updated on September 18, 2022Comments
-
Paweł Wojtal almost 2 years
I've tried to search this topic in google, but without any significant results.
I need to start some GUI app from terminal, but I don't care what this app is showing me. In addition, I need to start few instances of this application in different sessions. It's connected with some GUI automated tests, so I know what I want and I'm looking for an answer :).
I think the proper steps should be:
- Init new X window session
- Get my new session id
- export it to env variable (export DISPLAY:13.0)
- run my app
but I'm stuck at first step. does anybody here had similar problem?
--- EDIT: 1) I don't care about GUI output - i need only stdout and stderr from my app. - that's why this question is not duplicate - know google well :) . I don't want to redirect output to my own GUI.
-
Tim about 9 yearsI think you can just start an X and then run it.
-
Rmano about 9 yearsIt's not clear. Do you have a graphic desktop running locally? Or do you want to run an X application with no real display, neither locally nor remotely?
-
Rmano about 9 yearsLook at tldp.org/HOWTO/Remote-X-Apps.html --- maybe it can help.
-
Paweł Wojtal about 9 yearsRmano: I need to run app and click into it with robot-framework + selenium library - but I don't need to see any output from GUI, just logs from my scripts - is it an answer for your question?
-
daltonfury42 about 9 yearsit doesn't work for me. This is what I get.
-
Rmano about 9 yearsIf the remote myServer is running X, the default
DISPLAY
is:0
, not:1
. It will only work if the user you connect to (testSSH
) is the same one that is running the remote X server, otherwise auth tricks are needed. -
Rmano about 9 yearsSee also unix.stackexchange.com/questions/10121/… about the auth tricks.
-
Maythux about 9 years@Rmano It was just example and not real value, The OP must put the correct number
-
terdon about 9 yearsYou need
ssh -Y
orssh -X
. Exporting the display won't be enough. -
Maythux about 9 years
-
Paweł Wojtal about 9 yearsThere is also nice script provided with Xvfb - xvfb-run which is doing exactly this thing which I need: create virtual display and execute command passed as argument.
-
Ivan Ferrer Villa over 7 yearsperfect, thanks! to not block current session waiting to command return, add
&
after the command. To run a command in a remote Raspberry I usedlxterminal --working-directory=path-to-serverjs -e node server.js
. It opened Node in a new terminal on remote desktop. Eureka! Kisses. -
Abdull about 7 yearscommand prompt is
maythux@maythuxPC
, even when ontestSSH@myServer
? -
Scott Manley over 5 years
ssh -Y <username>@<host>
is what I prefer. superuser.com/a/123816 -
mchid over 5 years@rehctawrats You can also use compression:
ssh -CY <username>@<host>
but I haven't tried this out yet.