How to Use SSH X-forwarding to Run Remote Apps

Spread the love

There are times when it is just quicker, easier or even necessary to use a graphical application, and there are also times when you may be away from the computer that has your crucial applications installed.

Whatever the scenario, Linux and other operating systems running an X server have the ability to forward a graphical application through SSH. Following a few simple steps, you can run a remote application in all of its full graphical glory.

Note: if you are making multiple SSH connections to your remote machine, you can get your machine to show all active SSH connections.

Content

Installation and Setup

Before you begin, you need to make sure that the SSH client and server are installed on the correct computers. The host computer that has the actual running applications needs to have an SSH server running.

To install SSH, you need to run the following command on both your client and server machines:

sudo apt install ssh

The other important preliminary step is to make sure both computers are connected to a network and that you can reach them via SSH. If the computers are in the same building, it will be easy. If not, you may have to configure the host computer to receive SSH connections through the firewall. See your router’s documentation for the correct method of port forwarding.

Connecting to a Remote Server

  1. Open a terminal emulator: Gnome Terminal, Konsole or something similar.
  2. Connect to the host computer. As an example, if the host IP address is 192.168.68.155 and the host username is “ramces,” you would type the following:
ssh -X ramces@192.168.68.155

This tells SSH to start the X-forwarding server calls to the client computer.

  1. At the password prompt, enter the password.
  2. Run the application. For example, if you want to run Gedit, just type the command:
gedit &

Note: if you are using KDE, you will need to add “dbus-launch” before KDE applications. For example: dbus-launch kwrite &. Other applications that do not require D-Bus should work without it.

Automating and Securing SSH X-Forwarding

You should now be able to run remote X applications at will. This can be very helpful if, for example, you are running a computer with a very small hard drive, no hard drive or even one without a CD-ROM drive, all of which are common with many netbooks and low-cost mini desktops.

To automate this process, you could set up SSH public keys to connect without passwords and write an executable script. Also, if you need a full X session forwarded, you can use VNC technology through TigerVNC and x11vnc.

As with any network solution, you also need to make sure that your remote server is secure. Using SSH provides a secure connection, but it’s useless if your password is easy to guess and your firewall allows anyone to gain access to it.

Once you have a secure plan in place, remote X forwarding is an excellent way to load remote applications on demand and manage remote machines. The possibilities are only as limited to your imagination and the speed of your network connection.

Frequently Asked Questions

Can you use SSH X-Forwarding in Wayland systems?

Yes! You can easily use SSH X-Fowarding in Wayland by installing xwayland. This is a compatibility layer that serves to link Xorg-only applications to a purely Wayland environment. To install this, run sudo apt install xwayland.

Aside from that, you can also force SSH X-Forwarding in Wayland systems by replacing the “-X” flag with “-Y.” However, this alternative option is incredibly insecure. You need to make sure that you are in a closed, private network when you use this particular flag.

Why are some of my inputs in the remote application becoming lost.

This problem is most likely due to a latency issue between your local and remote machine. SSH X-Forwarding should be a reliable solution as long as there is less than 5000ms of lag between your local and remote machine, as the SSH client drops any exceedingly slow connection to protect it from a Slow Loris attack.

Can I access local files through my remote app with SSH X-forwarding?

No. By default, SSH X-forwarding only “streams” a GUI program from your remote machine to the display of your local computer so that a GUI program under X-forwarding behaves more like a projection than a hard copy of a program. Because of that, this remote GUI program will only be able to access the files that are also available in your remote machine.

Image credit: Unsplash. All alterations and screenshots by Ramces Red.

Subscribe to our newsletter!

Our latest tutorials delivered straight to your inbox

Sign up for all newsletters.
By signing up, you agree to our Privacy Policy and European users agree to the data transfer policy. We will not share your data and you can unsubscribe at any time. Subscribe


Ramces Red
Staff Writer

Ramces is a technology writer that lived with computers all his life. A prolific reader and a student of Anthropology, he is an eccentric character that writes articles about Linux and anything *nix.

Comments are closed