Most people regard ssh as a remote terminal, but it is much more. In this presentation we learn how to leverage ssh to run programs on a remote server and display their GUI X11 displays on your local desktop. This allows you to install programs on a remote server instance that could be a lean LXD container and run then from a desktop. This solves the problem of running a program that either is not compatible with your local desktop or a program that you do not want to locally install.
I start by creating a LXD Ubuntu server instance on my LXD host from a locally stored custom LXD image that includes a user account and the openssh-server. This server instance is bridged to the local LAN using skills we learned in my “Network Bridge vs Macvlan” video.
lxc launch Ubuntu-20.04 test --profile default --profile bridgeprofile -c boot.autostart=true
Copy ssh credentials to the server instance so we won’t have to authenticate each time:
ssh-copy-id username@172.16.1.145
ssh to the server instance and install updates and dependencies:
ssh scott@172.16.1.145
sudo apt update && sudo apt upgrade
sudo apt install x11-xserver-utils
Edit the ssh configuration file on the remote server:
sudo nano /etc/ssh/sshd_config
Make sure the the following lines are uncommented and appear like this:
X11Forwarding yes
X11DisplayOffset 10
Next, we rebooted the server instance.
We installed bluefish editor on the server as a test program:
sudo apt install bluefish
Test bluefish from a terminal on your local desktop:
ssh -X 172.15.1.145 bluefish
To automate launching the remote program, create a desktop file:
nano /home/scott/Desktop/Bluefish.desktop
Insert the following contents and update according to your needs:
#!/usr/bin/env xdg-open
[Desktop Entry]
Name[en_US]=Bluefish.desktop
Comment=Run Bluefish from Remote Desktop
Exec=/home/scott/Desktop/bluefish.sh
Terminal=false
Type=Application
Set the above file with execute privilege:
chmod +x /home/scott/Desktop/Bluefish.desktop
Create the script file referenced in the desktop file:
nano /home/scott/Desktop/bluefish.sh
Put the following contents in the script:
sh -X 172.16.1.145 bluefish
Give the script execute privilege:
chmod +x /home/scott/Desktop/bluefish.sh
You can now easily double-click the desktop icon to run bluefish on the remote server and display it on your local desktop display.
NOTE: An X11 application connects to Xwayland just like it would connect to any X server. Wayland provides backwards compatibility for legacy X11 applications. In order to use it, install the xorg-xwayland package.