There is how to set the environment variables in the destination, so that the program "find the screen" - in fact, it is only the variable "DISPLAY", since the user you use with SSH is the same as the one logged in graphic mode:
[usuario@host ~] export DISPLAY=:0
[usuario@host ~] <programa_desejado>
Or in the same line:
[usuario@host ~] DISPLAY=:0 <programa_desejado>
It is interesting to note that decades ago the X11 protocol used by Linux was created to allow you to run a program on the remote machine that shows the window interact on the machine from which you called.
If you want this, just make sure that in the server’s SSH configuration the option of X11Forwarding
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 - anyway it should 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 host screen- this is automatic when it connects from Linux/another machine with Posix and X11.
On Windows, Putty, the most popular SSH client, also supports this feature, but depends on installing a program that acts locally as an X11 server: https://the.earth.li/~sgtatham/Putty/0.70/htmldoc/Chapter3.html#using-x-Forwarding . On Mac you also need a program to act locally as X11 server.
With the gradual move to Wayland I don’t 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 as the one logged in graphic mode, simply set the DISPLAY variable to the value :0
on the same line that fires the app. See command help crontab -e
to do this, and put the DISPLAY variable before the command, as in the second example above.
The same DISPLAY variable allows Unix machines to run with a server for several thin-Terminals: you log into a different set of montior/keyboard/mouse and enter the machine with a different DISPLAY than ":0" (:1, etc....) - a single parruda machine allows multiple users. It was a common setup in universities in the 1990s. Today, with the great power of average Pcs, and the massive memory consumption of a typical desktop session (on account of HTML5 sites opened in tabs in browsers), this would hardly be worth it. But it could work - and it could survive, let’s say someone has a lab with several Pcs in good condition, but old, with about 1/2GB of memory - a new PC, with parruda CPU and some 32GB of memory could be the server, and the various old Pcs would just be thin-clients. For video/keyboard/mouse the setup is quite simple, using only these X11 client/server technologies - for the sound to exit correctly on each thin-client, complicates a bit.
Here it worked with the first export DISPLAY=:0 command after program name, thank you very much
– Marcelo