How to Set Up X11 Forwarding on Linux Over SSH

X11 forwarding lets you run a graphical Linux application on a remote computer and show its window on your local desktop through SSH. Set it up by enabling forwarding in the remote SSH server, confirming the server has xauth, checking that your local desktop has an X display, and connecting with ssh -X. This forwards individual application windows; it does not create a full remote desktop session.

What you need before setting it up

The computer where you type the SSH command is the client. It needs the OpenSSH client and an active graphical desktop session with an X display. Many Linux desktops provide this directly or through XWayland when the session uses Wayland. If echo "$DISPLAY" on the local desktop prints nothing, there is no display for SSH to use in that shell.

The remote computer is the server. It needs the OpenSSH server and the xauth utility so SSH can create the temporary authorization cookie used for the forwarded display. On Debian or Ubuntu, install them on the remote system with sudo apt update and sudo apt install openssh-server xauth. On another distribution, use its package manager to install the OpenSSH server and the package that provides xauth. Keep an ordinary SSH login working before changing the configuration.

Linux terminal showing the ssh and xauth commands found on the local system
Check that the local terminal can run the OpenSSH client; the remote server also needs xauth.

Set up X11 forwarding over SSH

1. Enable forwarding in the server configuration

On the remote computer, edit the server configuration file, usually /etc/ssh/sshd_config, using an editor with administrator privileges:

sudoedit /etc/ssh/sshd_config

Find an existing active X11Forwarding setting and change it to:

X11Forwarding yes

If the setting is absent, add it in the global section before any Match block. Some distributions also load files from /etc/ssh/sshd_config.d/; check included files for conflicting settings. A Match rule or DisableForwarding yes can still prevent forwarding for a particular account. Leave X11UseLocalhost at its default unless you have a specific compatibility problem: OpenSSH normally binds the forwarding proxy to loopback. The official sshd_config manual describes these server-side options.

SSH server configuration with the active X11Forwarding yes directive
The server setting belongs in sshd_config, not the SSH client file ssh_config.

2. Validate the configuration and reload SSH

Before reloading the daemon, check the file for syntax errors and confirm the effective forwarding value:

sudo sshd -t
sudo sshd -T | grep -i '^x11forwarding'

The first command should exit without an error; the second should report x11forwarding yes. If you use Match rules, test the effective configuration for the relevant user and connection as described in the OpenSSH manual. Fix any error before reloading so you do not disrupt SSH access.

Reload the service name used by your distribution. Debian and Ubuntu commonly use:

sudo systemctl reload ssh

Fedora and RHEL-family systems commonly use:

sudo systemctl reload sshd

If reload is unsupported, use restart for the same service. Keep the current session open and test a new connection before closing it. Ubuntu's OpenSSH server documentation covers the server file and configuration snippets used on Ubuntu.

3. Connect from the local Linux desktop

On the client, request untrusted X11 forwarding with -X:

ssh -X user@server.example.com

Replace the example username and host with your own. If the SSH server listens on a nonstandard port, add its port number with -p:

ssh -X -p 2222 user@server.example.com

After signing in, start a graphical program that is installed on the remote host. For a quick check, run xclock if that test application is available, or launch another installed GUI program. SSH sets the remote session's DISPLAY value and forwards the X11 connection automatically; do not copy your local display value to the server or set it by hand.

Local Linux terminal connecting to a remote host with ssh -X
The -X option requests X11 forwarding when the SSH session starts.
Remote xclock application displayed beside the SSH terminal on a Linux desktop
A forwarded GUI application appears as a window on the local desktop while the SSH session stays open.

Security and troubleshooting

Use -X by default. The -Y option enables trusted forwarding, which removes X11 SECURITY restrictions and gives the remote application broader access to your local display. Use it only with a server and application you trust. OpenSSH warns that X11 forwarding can expose the client display to attacks; see the ssh manual and ssh_config manual for the distinction between trusted and untrusted forwarding.

  • “X11 forwarding request failed”: Check the server's effective X11Forwarding value, confirm xauth is installed on the remote host, and look for a restrictive Match block or DisableForwarding setting.
  • DISPLAY is empty on the remote session: Disconnect and reconnect with ssh -X. Confirm the local shell has a running graphical display and that the connection reaches the server you just configured.
  • The window says it cannot open a display: Verify that your local desktop session is still active. A shell without access to the desktop display cannot show forwarded windows.
  • xclock is not found: The test program is simply absent. Try a GUI application already installed on the remote machine; this message alone does not prove SSH forwarding is broken.

X11 forwarding is convenient for occasional remote tools, but graphical applications that redraw frequently can feel slow over a high-latency connection. For an entire desktop or graphics-heavy work, use a remote desktop solution designed for that job.

Leave a Comment

How to Record Speaker Output on Linux with Audacity

How to Record Speaker Output on Linux with Audacity

Capture Linux desktop audio in Audacity by routing its recording stream to your output device’s monitor source. Follow PulseAudio and PipeWire steps, export tips, and fixes for silent tracks.

How to Use Dropbox on Linux: Install and Sync Your Files

How to Use Dropbox on Linux: Install and Sync Your Files

Install Dropbox on Linux from the official package, sign in, sync a local folder, manage selective sync, and check status from the command line.

How to Install Inkscape on Linux: Ubuntu, Fedora, Arch, and More

How to Install Inkscape on Linux: Ubuntu, Fedora, Arch, and More

Install Inkscape from your Linux distribution’s repositories, the Ubuntu stable PPA, Snap, or Flathub, with current commands and notes for choosing a package source.

How to Find and Remove Duplicate Files on Linux With FSlint

How to Find and Remove Duplicate Files on Linux With FSlint

Use FSlint to scan selected Linux folders, review duplicate groups, and safely delete redundant files or learn when hard-link merging is appropriate.

How to Install SABnzbd on Linux and Configure It

How to Install SABnzbd on Linux and Configure It

Install SABnzbd on Ubuntu or Debian, or run it in Docker on another Linux host. Then open the web interface and configure your provider and download folders.

How to Install the Paper GTK Theme on Linux

How to Install the Paper GTK Theme on Linux

Install the Paper GTK theme from supported Linux repositories, enable it for GTK apps in GNOME Tweaks, and see what the legacy theme can and cannot change.

How to Install and Set Up Plex on OpenMediaVault with Compose

How to Install and Set Up Plex on OpenMediaVault with Compose

The old OpenMediaVault Plex plugin is archived. Set up Plex on OMV 8 with OMV-Extras, the Compose plugin, persistent storage, and Plex’s official container.

How to Clean and Speed Up Ubuntu Safely

How to Clean and Speed Up Ubuntu Safely

Clean and speed up Ubuntu with safe APT cleanup, storage checks, and startup controls that help free space and troubleshoot a sluggish desktop.

How to Install the Hiri Email Client on Linux

How to Install the Hiri Email Client on Linux

Install Hiri on Linux with its Snap package or official tarball, add a desktop launcher, and check supported accounts plus a warning about Hiri’s old Snap release.

How to Get System Specifications for a Linux PC

How to Get System Specifications for a Linux PC

Use Fastfetch and built-in Linux commands to check your distro, kernel, CPU, memory, graphics, storage, and connected devices, then save a clear report.