How to run application on linux desktop remotely via command?

3

I have a server on a client where I use a remote application, sometimes some user goes there and closes the application (I do not know if I accidentally or the owner, for fear), then I can not connect.

The application automatically starts when I restart the server, but I can not restart the server during working hours.

I have access to the command line of this server via ssh and could run the application, but as it is visual, the error remotely because it understands that I want to run it on the network.

I was thinking of creating a cron only to run the application shortcut so that it opens it on the server screen, I do not know if it is the best way and if it is possible.

In summary, I need to run an application on the Linux desktop remotely via ssh (Kubuntu 16.x) remotely.

Any tips?

    
asked by anonymous 18.06.2018 / 21:36

1 answer

6

You can set the environment variables in the destination so that the program "finds the screen" - in fact, it is only the variable "DISPLAY", as long as the user you use with SSH is the same as the one logged in graphical mode:

[usuario@host ~] export DISPLAY=:0
[usuario@host ~] <programa_desejado>

Or on the same line:

[usuario@host ~] DISPLAY=:0 <programa_desejado>

It's interesting to note that for decades the X11 protocol used by Linux has been created to allow you to run a program on the remote machine that shows the window interacting on the machine you called from.

If you want this, just make sure that in the server's SSH configuration the X11Forwarding option is enabled (in Fedora the file is in /etc/ssh/sshd_config , if it is not the same file in Debian / Ubuntu it is similar - of any form must be enabled by default)

And then when connecting with SSH you use the option -Y :

[usuario@hostlocal ~] ssh -Y hostremoto
[usuario@hostremoto ~] <nome_do_programa>

and the program appears on the local host screen - this is automatic when connecting from Linux / another machine with Posix and X11.

On Windows, PuTTY, the most popular SSH client, also supports this functionality, but depends on the installation of a program that acts locally as an X11 server: link . On the Mac you also need a program to act locally as an X11 server.

With the gradual change to Wayland I do not know if these features will be maintained.

To run a graphical program from CRON, the idea is the same: if the user is the same one that is logged in graphical mode, simply set the DISPLAY variable to the value :0 on the same line that triggers the application . See the help of the crontab -e command to do this, and put the DISPLAY variable before the command, as in the second example above.

The same variable DISPLAY allows Unix machines to work with a server for several thin-terminals: you log into a different set of montior / keyboard / mouse and enter the machine with a DISPLAY other than ": 0" (: 1, etc. ....) - a single machine allows several users. It was a common setup at universities in the 1990s. Today, with the sheer power of average PCs, and the high memory footprint of a typical desktop session (because of HTML5 sites opened in tabs in browsers), it would hardly be worth it . But it could work - and it could give a survival, let's say that someone has a lab with several good but old PCs, with about 1 / 2GB of memory - a new PC with CPU and a 32GB memory could be the server, and the various old PCs would be just like thin-clients. For video / keyboard / mouse setup is very simple, using only these X11 client / server technologies - for the sound to come out correctly on each thin-client, it complicates a bit.

    
18.06.2018 / 22:32