This tutorial walks through running a graphical application remotely via X11 forwarding. The local machine is assumed to be running the OpenSSH client and likewise the server is assumed to be running the OpenSSH server. X11 must be available on both the client and server.
Although X11 is being superseded by Wayland, many Unix-like systems still ship with some form of X11 today. Wayland also specifies features for compatibility with X11, so X11 forwarding might continue to work even under your system’s implementation of Wayland. On macOS, the X11 software is available from the XQuartz project.
Ensure the SSH server has the required
➜ which xauth /usr/bin/xauth
On the SSH server, set
ForwardX11 yes in
sshd_config to enable X11 forwarding.
Open an SSH connection with X11 forwarding by adding the
-X flag on the command-line.
➜ ssh -CX mordor
If you receive a warning that the file
Enable compression when using X11 forwarding with the
If the graphical application your using requires fully trusting X11, use the
-Y flag instead.
➜ ssh -CY helms-deep
|Your key presses can be captured on the remote machine so make sure you actually trust it.|
From the terminal, execute a graphical application, and it will be displayed locally so long as nothing goes awry.
Execute GNOME Terminal, for instance.
If you always require X11 forwarding when connecting to a particular host, add the relevant options to enable it in your SSH client’s configuration.
Host helms-deep Compression yes ForwardX11 yes ForwardX11Trusted yes
|Never indiscriminately enable X11 forwarding.|
Optionally, background the SSH process when running a remote X11 application.
It’s not necessary to keep a dedicated terminal open with the SSH process running.
-f flag to execute a program on the remote machine and background the SSH process.
The following example demonstrates this by running GNOME Terminal on the remote host.
➜ ssh -CYf helms-deep gnome-terminal
You should now be able to take advantage of X11 forwarding built into OpenSSH to run graphical applications on a remote machine while viewing them locally.