Apple OS X: Install X Window System (XQuartz) For SSH X11 Forwarding

by on November 11, 2013 · 6 comments· LAST UPDATED November 11, 2013

in , , ,

I need to tunnel X Window securely over SSH bases session so that I run X program on my remote Linux/Unix server/workstation and get back display to my Apple Macbook pro laptop. I tried the ssh -X user@server1ssh -Y user@server2 command on both OS X Mountain Lion and Apple OS X Mavericks. But, I am unable to use the ssh command with X11

How do I fix this problem on OS X and enable X11 forwarding with ssh command? How do I install XQuartz (X11.app) server on Apple OS X Mountain Lion or Mavericks?

Tutorial details
DifficultyIntermediate (rss)
Root privilegesYes
RequirementsOS X v10.8/10.9+
Estimated completion time10m
You need to install XQuartz (X11.app) on OS X v10.8 or above to use ssh with x11 forwarding. The XQuartzproject is an open-source effort to develop a version of the X.Org X Window System that runs on OS X. This is Apple's version of the X server.

The latest version of Apple OS X Mountain Lion and Mavericks no longer ships with X11.app i.e. XQuartz server. You need to download and install the server before using ssh with X11 forwarding.

Step #1: Download and Install XQuartz server

Visit this page and download XQuarz server. Once downloaded the XQuarz package, install the server by double clicking the package icon in your Downloads folder. Please follow the instructions on-screen to complete the installations.

Step #2: ssh X11 forwarding syntax

A tunneling protocol is a network protocol which encapsulates a payload protocol, acting as a payload protocol. Reasons to tunnel include carrying a payload over an incompatible delivery network, or to provide a secure path through an untrusted network. SSH is frequently used to tunnel insecure traffic over the Internet in a secure way. Simply type the following command to use X over ssh:

 
ssh -X user@RemoteserverNameHere
x-app-name-here &
 

OR

 
ssh -X userName@Server-Ip-Address-Here
x-window-app-name-here &
 

Examples

In this example, login to the Linux based nas01 server as a user called nixcraft:
$ ssh -X nixcraft@nas01
OR
$ ssh -X nas01
You will see XQuartz server in the Dock i.e. a new XQuartz icon sits at the bottom of side of your screen as follows:

Fig.01: X11.app ( XQuartz ) loaded at the Dock

Fig.01: X11.app ( XQuartz ) loaded at the Dock


To test X11 by running xeyes or xclock or any another GUI application you wish. The syntax is as follows on your remote server:
$ app-name
$ /path/to/app-name
$ app-name &

In this example, I am running xeyes on remote server:
$ xeyes
Sample outputs:
Animated gif 01: X11 Forwarding on OS X v10.8+. This demo was tested on OS X 10.9 i.e. Mavericks and Linux remote server.

Animated gif 01: X11 Forwarding on OS X v10.8+. This demo was tested on OS X 10.9 i.e. Mavericks and Linux remote server.

Edit your ~/.ssh/config file and append the following line and you wouldn't need pass the -X option to ssh command:

ForwardX11 yes

Finally, you can run ssh in the background after running a GUI app as follows:

ssh user@server -f -X app-Name
ssh nixcraft@nas01 -f -X gpass
ssh nixcraft@nas01 -f -X xeyes
See also
TwitterFacebookGoogle+PDF versionFound an error/typo on this page? Help us!

{ 6 comments… read them below or add one }

1 Debjit Saha January 13, 2014 at 2:25 am

How can I start other apps such as Firefox or XCode. One running them using open command, these apps are opening in the remote mac system not in my ssh terminal

Reply

2 Tom Cox March 4, 2014 at 11:50 pm

When you say this:

To test X11 by running xeyes or xclock or any another GUI application you wish. The
syntax is as follows on your remote server:
$ app-name
$ /path/to/app-name
$ app-name &

are these three alternatives?

Reply

3 GTFO March 21, 2014 at 8:22 am

Yup. If xclock is in PATH, you can type the following on remote host:

xeyes

If xeyes is not in the PATH, type full path such as:

/usr/local/bin/xeyes

Reply

4 sunny March 5, 2014 at 4:32 am

How can I start other apps such as Firefox or XCode. One running them using open command, these apps are opening in the remote mac system not in my ssh terminal

Reply

5 Nico van der Linden March 5, 2014 at 10:00 am

Do anyone know if you can use XQuartz on a DIFFERENT user as which you logged on to the SSH session? I work for some customers where you must logon with a network account and a token to the linux environment and from there you can su into other users.

The X-forward runs fine for the user I used to logon but when I su in a different user it does not accept it anymore. On windows I always used Exceed and there you had to set a “DISPLAY” variable under the account you used to run the X application. So if that can be used with XQuartz then it would be fine as well.

Kind Regards,
Nico van der Linden

Reply

6 GTFO March 21, 2014 at 8:26 am

Use sux command – a wrapper around su which will transfer your X credentials to the target user. If sux is not installed try xauth command.

Reply

Leave a Comment

Tagged as: ,

Previous Faq:

Next Faq: