How to start a graphical interface application on remote Linux server from Mac OS via SSH and X11 forwarding? A 5 minutes tutorial

Today I want to share how to run a graphical interface application on remote Linux server from Mac OS. In my daily work, it happens that we often need to use SSH to connect to a remote server.

SSH: the easy way

In case you don’t know how that works, it’s as simple as it can be. On Mac OS, open terminal and type:

ssh <remote_user_name>@<remote_IP_address>

That’s all you need. This post assumes you already know why you are connecting to a remote server and you have a remote server running which you can ssh to. SSH comes in quite handy for me in daily work. For example, I have a few Linux VMs running headless on my Mac OS host, and I use ssh to connect to them and do stuffs. I also use SSH to connect to my Raspberry Pi server. If you want to know how to set up SSH server, check out my previous post.

X11 forwarding

Our question here is how do we start a GUI program on the remote machine, and we want to see the interface locally. Sometimes it is just more convenient.

For example, when I want to quickly inspect packet logs using wireshark, or just quickly log in to an account using FireFox on the remote machine. What we need to enable this scenario is called “X11 forwarding”. It is a way to allow us to start a remote applications, and forward the display to our local machine.

Setting up on Mac OS and give it a try

On Mac OS, this just needs a little bit of work.

  1. We first need to install XQuartz. It’s an X server software on Mac OS. X11 forwarding forwards the display to the X server.
  2. Once installed, start XQuartz from Applications.

3. We should now see XQuartz appears on the dock. We can right-click on it and bring a xterm terminal. Or, alternatively, just start the Mac OS terminal.

4. We can then connect to our remote server with X11 forwarding. This requires the -X option.

ssh -X <remote_user_name>@<remote_IP_address>

5. You are now logged in to your remote server. Try to start a GUI from command line. My remote machine is a Ubuntu 18.04 machine and it has Firefox installed. So I would use FireFox:

firefox

Done! We have an Ubuntu FireFox window showing up on Mac OS.

Leave a Reply Cancel reply