23

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:

  1. Init new X window session
  2. Get my new session id
  3. export it to env variable (export DISPLAY:13.0)
  4. 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.

4
  • I think you can just start an X and then run it.
    – Tim
    Jun 8, 2015 at 13:48
  • It'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
    Jun 8, 2015 at 14:05
  • Look at tldp.org/HOWTO/Remote-X-Apps.html --- maybe it can help.
    – Rmano
    Jun 8, 2015 at 15:08
  • Rmano: 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? Jun 8, 2015 at 15:35

3 Answers 3

24

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
1
  • 2
    There 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. Jun 9, 2015 at 7:00
19

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.

  1. 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
    
  2. Check /etc/ssh/ssh_config on the client side:

    sudo nano /etc/ssh/ssh_config
    

    for the lines below

    ForwardX11 yes
    ForwardX11Trusted yes
    
2
  • 3
    ssh -Y <username>@<host> is what I prefer. superuser.com/a/123816 Nov 19, 2018 at 6:19
  • 1
    @rehctawrats You can also use compression: ssh -CY <username>@<host> but I haven't tried this out yet.
    – mchid
    Mar 2, 2019 at 6:24
12

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"
8
  • it doesn't work for me. This is what I get. Jun 8, 2015 at 14:51
  • 3
    If 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
    Jun 8, 2015 at 14:57
  • See also unix.stackexchange.com/questions/10121/… about the auth tricks.
    – Rmano
    Jun 8, 2015 at 15:11
  • @Rmano It was just example and not real value, The OP must put the correct number
    – Maythux
    Jun 8, 2015 at 15:33
  • You need ssh -Y or ssh -X. Exporting the display won't be enough.
    – terdon
    Jun 8, 2015 at 15:41

Not the answer you're looking for? Browse other questions tagged .