💾 Archived View for vps-775853f2.vps.ovh.net › tutorials › run-graphical-programs-remotely-X11Forwar… captured on 2022-03-01 at 15:13:52. Gemini links have been rewritten to link to archived content

View Raw

More Information

-=-=-=-=-=-=-

X11Forwarding - run graphical programs remotely

This is a Linux howto. (Similar probably works on BSDs, Windows?)

Justification

If you are in geminispace then you are probably familiar with ssh-ing into remote computers on the internet. For most people this is always through a terminal. Text only. The remote computer(server) is usually headless, i.e. it does not run a gui, desktop environment etc. But what if occasionally you want to run a graphical program on the remote computer and interact with it on the computer from which you are ssh-ing in. Or share a clipboard between computers(see section Killer App below). That's where X11Forwarding comes in.

X11Forwarding is so called because the display server(which handles graphics) is called X. And the graphical program is forwarded over the internet to your local machine.

It is actually quite easy to set up.

Config files

The two files that need to be edited are the sshd_config file on the ssh server into which you are ssh-ing and the ssh_config file on your local machine.

On the ssh server, in the /etc/ssh/sshd_config configuration file include a line as follows:

X11Forwarding yes

You will need to use sudo: e.g. "sudo vi /etc/ssh/sshd_config" or "sudo nano /etc/ssh/sshd_config" etc.

Make sure it is not commented out with a hash sign:

#       X11Forwarding yes 

On the local machine, in the /etc/ssh/ssh_config (or ~/.ssh/.ssh_config if set on a per-user basis*) configuration file include lines as follows:

       ForwardX11 yes 
       ForwardX11Trusted yes 
ssh -F ~/.ssh/ssh_config gemini-user@remoteserver.xyz

Run the graphical program

Once you have ssh-ed into the remote server you can enter "echo $DISPLAY" on the command line. Usually on a headless server a blank will be echoed but if X11Forwarding is working something like "localhost:0.0" should be output.

Now you can try running a graphical program such as xed or gedit. If none is installed try "sudo apt install gedit". Since many servers don't have graphical dependencies installed by default even a small program might require 200MB of the graphical dependencies to be downloaded also. To run the program and also maintain use of the terminal append the & symbol when running your program:

gedit&

The graphical program should now pop up on your local machine. Any files that are saved in a text editor will be saved on the remote machine.

Killer app

Even if you never would use remote programs like this there is one intriguing usage for which X11Forwarding is very useful: clipboard sharing. If you have ever used a program such as xclip or xsel to pipe terminal output into the clipboard and then paste it into another application but have to resort to highlighting text with your mouse from a remote ssh session then if you set X11Forwarding up you can do something like "cat myfile.txt | xclip -i" and then paste it in the terminal of the other computer: "xclip -o >> myfile.txt". Very useful.

Caveats

Security-wise if you are not sure about who has access to either computer and have valuable files make sure to search online for appropriate guides before trying this out.

Depending on your internet connection speed the performance varies. On a very fast connection it can be indistinguishable from running the program locally. On a slow connection expect a delay of between 2 and 20 seconds(very slow) before the program pops up on your local screen.

Published 2 Feb 2022