How to enable X11 forwarding using SSH

Last updated on November 14, 2020 by Dan Nanni

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 on both server-side and client-side configurations.

Server-Side Preparation

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

Enable X11 Forwarding System-wide

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

Enable X11 Forwarding on a Per-User Basis

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

Client-Side Test

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.

Support Xmodulo

This website is made possible by minimal ads and your gracious donation via PayPal or credit card

Please note that this article is published by Xmodulo.com under a Creative Commons Attribution-ShareAlike 3.0 Unported License. If you would like to use the whole or any part of this article, you need to cite this web page at Xmodulo.com as the original source.

Xmodulo © 2021 ‒ AboutWrite for UsFeed ‒ Powered by DigitalOcean