How to start X application from SSH [duplicate]

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

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
    

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"