How to enable X11 forwarding using ssh

X11 forwarding is a mechanism that allows graphical interfaces of X11 programs running on a remote Linux server to be displayed on a local client machine. Behind the scene, the X11 output of a remotely running program is authorized to be sent to localhost via an X11 connection between client and a remote server. SSH has an option to securely tunnel such X11 connections, so that X11 forwarding sessions are encrypted and encapsulated. If you would like to set up X11 forwarding over SSH, check out this guideline.

For X11 forwarding, the remote server host doesn't need to have a full X11 system installed. However, at least the server host needs to have xauth installed. xauth is a utility that maintains Xauthority configurations used by server and client for authentication of X11 sessions. To install xauth, do the following on a remote server.

For Debian etch (4.0) and earlier, and Ubuntu 7.04 and earlier:

$ sudo apt-get install xbase-clients

For Debian lenny (5.0) and higher, and Ubuntu 7.10 and higher:

$ sudo apt-get install xauth

Then, enable X11 forwarding in sshd, and restart sshd as follows.

$ sudo vi /etc/ssh/sshd_config
X11Forwarding yes
$ sudo /etc/init.d/sshd restart

The above setup enables X11 forwarding system wide on the server host. If you would instead like to enable X11 forwarding on an individual user basis, you can use user-specific ssh configuration file (i.e., $HOME/.ssh/config). That way, you can use X11 forwarding only when you ssh to the user's account.

$ vi $HOME/.ssh/config file
ForwardX11 yes

Unlike a remote server host, a local client machine needs to have X11 system installed, in order for the display of remotely running X11 programs to be shown. Assuming that is the case, you can open ssh connection from a local machine to the remote server as follows.

$ ssh -X user@remote_server

Once logged in, you can launch any X11 program on the remote server as usual, and its display will be shown on the local client machine.

Subscribe to Xmodulo

Do you want to receive Linux FAQs, detailed tutorials and tips published at Xmodulo? Enter your email address below, and we will deliver our Linux posts straight to your email box, for free. Delivery powered by Google Feedburner.

Support Xmodulo

Did you find this tutorial helpful? Then please be generous and support Xmodulo!

The following two tabs change content below.
Dan Nanni is the founder and also a regular contributor of He is a Linux/FOSS enthusiast who loves to get his hands dirty with his Linux box. He likes to procrastinate when he is supposed to be busy and productive. When he is otherwise free, he likes to watch movies and shop for the coolest gadgets.

One thought on “How to enable X11 forwarding using ssh

  1. Hey, just wanted to say thanks for this article. I've only ever configured X-Forwarding once before and it was a couple years ago. I recently purchased a VPS to run a game server off of, configured putty, authorized keys for passless login, and installed ming - and couldn't figure out why X applications weren't working until I stumbled upon this page. So thanks again!

Leave a comment

Your email address will not be published. Required fields are marked *