It’s possible to view and control remote GUIs using SSH’s X11 forwarding protocol, so you can run an application on a remote server as if it was being run locally. Of course, doing so is not without lag and some interesting graphical effects, but it can prove highly useful in the case that you need to physically see what an application is rendering remotely.
Some weeks ago I was automating Google Chrome on a remote machine, and at some point it had to log in to Google. Because the remote machine was in an IP range probably recognised by Google as being an unlikely origin for a human user, it had presented my automation with a verification challenge.
Being that I didn’t particularly feel like attempting to automate SMS messages to a phone, I decided to try logging in manually on the instance to see if Google would then trust the instance and/or IP range. The trouble was, the instance was simply an Ubuntu server with no GUI environment to connect to.
Using SSH, however, I was able to use X11 window forwarding to pipe the Chrome window to my local machine so I could perform the login at my workstation. X11 can’t exactly be used out of the box and requires a few tweaks to both the server and client to enable it.
Firstly, the server needs to have the following in
The default is no forwarding, so this is a mandatory step as most servers will not have it enabled. You’ll need to restart SSH for this to take effect.
When executing a forwarding request on the client, you need to specify the
-X (capital “X”) argument to enable forwarding. You can force this on by default by adding the following to
The SSH command should contain the program you’ll be forwarding from. In my case it was the
ssh -X email@example.com google-chrome
After some moments and concerning-looking log messages, you’ll most likely see a Chrome window open on your machine. Don’t expect a responsive experience as the streaming of GUIs doesn’t seem to be highly optimised.
This post assumes you’re forwarding on Linux, but it’s definitely possible to do the same on a Mac client using XQuartz.
XQuartz will most likely require you to restart your Mac, but once working it’ll handle forwarded windows in much the same way as a Linux client would.