Sunday, July 2, 2017

Exporting X Session From Linux to Mac

I primarily work on Linux and Mac for different reasons, firstly for the fun of it, and I get to savour the best that these different Operating Systems has to offer. There are times I would like to take some dev work onto my Mac, however, the app resides on my Linux host that requires a graphical environment that is exclusive on my Linux host. This graphical session is known as Xwindow system. With Xwindow, you can export graphical sessions to another host to run apps without having to install the app on the machine that you are running it on! That means you can run Linux apps on a Mac or Windows host.

The traditional method was to export Xwindow using the 'xhost +myremotehost.com' and 'export DISPLAY=myremotehost.com:0.0' command, but it also requires me to poke more holes in my firewall to allow the Xwindow session thru. This method is not recommended as there are known security risks associated with exporting X remotely as the session can be sniffed or worse hijacked. One way to securely export Xwindow is to use the built X11 forwarding function in OpenSSH. It allows you to export Xwindow via a ssh session that is encrypted by default.

On the Linux host where the graphical apps resides, ensure the following lines are enabled in /etc/ssh/sshd_config:

X11Forwarding yes

X11DisplayOffset 10

Make sure you restart/reload ssh after making changes.

If you are running MacOS 10.x and above, you will need to download XQuartz. Unfortunately, newer MacOs do not support the same X server that Linux does. Further instructions on where and how to download XQuartz can be found, here.

Once that is done, on your Mac host, launch XQuartz -> Application -> xterm and ssh to your Linux host with the -X flag:


Once you have successfully authenticated, just launch your fav X application:


There you go! You now have a Linux app that runs on Mac. Pretty cool huh? Well for me atleast :-p


No comments:

Post a Comment