You need one graphical tool from a remote Linux box: a profiler, virt-manager, a Wireshark capture, an old Java installer that refuses to run headless. SSH X11 forwarding lets that program run on the server and draw its window on your screen, over the SSH connection you already have. When it works it takes one flag. When it doesn't, you get cannot open display, a silent empty $DISPLAY, or "X11 forwarding request failed on channel 0", and none of them say which side is broken.
This guide covers the setup on Linux, macOS and Windows (through WSL), what -X and -Y really change, and a fix for each error message. Every error below was reproduced on a lab sshd running OpenSSH 9.6p1 on Ubuntu 24.04, with Xvfb standing in for the local X server.
Quick Summary: What You'll Learn
- The three things X11 forwarding needs, and a 30-second test that proves it works.
- The difference between
ssh -Xandssh -Y, and why they behave the same on Debian and Ubuntu clients. - What each X11 error means: server-side, client-side, or a cookie problem.
- How to get a remote window on macOS (XQuartz) and on Windows (WSL).
- When X11 forwarding is the wrong tool, and what to use instead.
How do you set up SSH X11 forwarding?
X11 forwarding needs three things, and every failure is one of them missing:
- An X server on your machine. On Linux desktops running Xorg or XWayland you already have one. On macOS you install XQuartz. On Windows, WSL 2 ships one (WSLg).
-
DISPLAYset on your machine, sosshknows where to send the windows. -
A server that allows it:
X11Forwarding yesinsshd_configand thexauthprogram installed.
Then connect with -X:
ssh -X user@server
Check it from the remote shell before you launch anything heavy:
echo $DISPLAY
# localhost:10.0
If DISPLAY reads localhost:10.0 (or :11.0, :12.0 for later sessions), forwarding is up. Start a small X program to confirm the round trip. xdpyinfo | head -3 (package x11-utils on Debian and Ubuntu) prints the display name and the vendor of your local X server; xeyes (package x11-apps) opens a window you can see.
On the server side, Debian and Ubuntu already set X11Forwarding yes in the stock /etc/ssh/sshd_config, which is easy to miss because the upstream default is no. A minimal server often lacks xauth, though. On Ubuntu or Debian:
sudo apt install xauth
sudo sshd -T | grep -iE 'x11|xauth'
sshd -T prints the effective configuration, after every Include and drop-in file is applied. You want to see:
x11displayoffset 10
x11forwarding yes
x11uselocalhost yes
xauthlocation /usr/bin/xauth
If you change sshd_config, validate with sudo sshd -t before reloading, and keep your current session open until a new login works.
What does ssh -X actually do?
Knowing the moving parts makes the error messages readable.
- Your client sends an
x11-reqrequest for the session. - sshd opens a proxy display on the server, starting at display 10 (
X11DisplayOffset), bound to the loopback address (X11UseLocalhost yes), and setsDISPLAY=localhost:10.0in your session. - sshd runs
xauthon the server to store an authentication cookie for that display in~/.Xauthority. In debug output this is literallyxauth add unix:10.0 MIT-MAGIC-COOKIE-1 <hex>. - A remote program connects to
localhost:10. sshd carries the connection back over the SSH channel, and your client checks the cookie and swaps it for the real one your local X server expects.
So the server never learns your local X server's real cookie, and nothing outside the server's loopback can reach the proxy display. Step 4 is also why a cookie mismatch shows up as an error printed by your local ssh, not by the server.
Should you use ssh -X or ssh -Y?
-X asks for untrusted forwarding: remote programs are restricted by the X11 SECURITY extension, so they can't read other windows or snoop on input to them. -Y asks for trusted forwarding, with full access to your display. Under the upstream default, an untrusted cookie also expires after 20 minutes (ForwardX11Timeout), and new windows opened after that are refused with:
Rejected X11 connection after ForwardX11Timeout expired
Debian and Ubuntu patch the client so ForwardX11Trusted defaults to yes. The ssh(1) man page there says it directly: X11 forwarding is not subjected to the SECURITY extension by default "because too many programs currently crash in this mode". On those clients, -X and -Y behave the same, which our lab confirmed. To see what your own client does:
ssh -G server | grep -i forwardx11
# forwardx11 no
# forwardx11trusted yes
# forwardx11timeout 1200
ssh -G prints the configuration ssh would use for that host without connecting. forwardx11trusted yes means you are already in trusted mode.
Which one to pick: use -X first. If the program crashes, renders badly, or loses its windows after 20 minutes, and you trust the server, use -Y. Treat -Y like agent forwarding: anyone with root on that server can reach your display while you're connected. More on that below.
Why is X11 forwarding not working?
Match the exact message to its cause. All of these were reproduced in the lab unless the section says otherwise.
"X11 forwarding request failed on channel 0"
The client asked and the server said no. Two causes produce this same client message:
-
X11Forwarding noin the effective config. The server log (withLogLevel DEBUG1orsshd -d) showsX11 forwarding disabled in server configuration file. - sshd cannot run
xauth. We pointedXAuthLocationat a missing path and got the identical client message.
Both are visible in one command on the server:
sudo sshd -T | grep -iE 'x11forwarding|xauthlocation'
ls -l "$(sudo sshd -T | awk '/^xauthlocation/ {print $2}')"
Watch for a drop-in in /etc/ssh/sshd_config.d/ or a Match block that sets X11Forwarding no for your user or group. To check a specific user, add the connection details: sudo sshd -T -C user=alice,host=laptop,addr=203.0.113.5. A third source is the no-X11-forwarding option on your key's line in authorized_keys, which sshd logs as X11 forwarding disabled by key options.
DISPLAY is empty on the server and there's no error
You typed ssh -X, logged in fine, and echo $DISPLAY prints nothing. Remote programs then fail with:
xdpyinfo: unable to open display "".
This one is on your side. If your local DISPLAY is unset, ssh quietly skips the request. Only ssh -v tells you:
debug1: X11 forwarding requested but DISPLAY not set
Run echo $DISPLAY locally. Empty means no X server is running in that environment: XQuartz not started on macOS, a plain terminal in a non-graphical session, or a Windows shell outside WSL. Fix the local side, then reconnect. Don't set DISPLAY by hand on the server to a value like :0: that points at the server's own screen, not yours.
"Warning: No xauth data; using fake authentication data for X11 forwarding."
Usually harmless. Your client couldn't find a cookie for your local display in its own ~/.Xauthority (common when the local X server runs without authentication), so it made one up for the server side. Forwarding still worked in every lab run that printed this. If remote windows then fail with an authorization error, run xauth list locally and make sure your local X server and XAUTHORITY agree.
"X11 connection rejected because of wrong authentication."
The remote program reached the proxy display with the wrong cookie, or none at all. Your local ssh prints this, and the program reports unable to open display "localhost:10.0". The classic trigger is sudo or su: the new user has a different home and no copy of the cookie sshd stored in yours.
Copy the cookie for this display to the other user's authority file:
xauth extract - "$DISPLAY" | sudo -u otheruser xauth merge -
sudo -u otheruser env DISPLAY="$DISPLAY" xeyes
In the lab, the same program failed with XAUTHORITY=/dev/null and worked after xauth extract | xauth merge into a second file. The DISPLAY part matters because sudo normally resets the environment. Check your sudoers before relying on sudo -E.
"xauth: file ~/.Xauthority does not exist"
Harmless on the first X11 login to an account. sshd's xauth add creates the file and prints this once. Nothing to fix.
"Failed to allocate internet-domain X11 display socket."
We didn't reproduce this one; the string is in OpenSSH's sshd and appears in its log when sshd can't open the proxy display. The usual report is a server with IPv6 disabled while sshd tries to bind IPv6 too. The commonly used fix is AddressFamily inet in sshd_config (restricts sshd to IPv4), followed by sshd -t and a reload. A display number range that is fully taken by stale sessions can also block it; ss -ltnp | grep ':60' shows who holds ports 6010 and up.
How do you use X11 forwarding on a Mac?
macOS has no built-in X server. Install XQuartz from xquartz.org (the current release, 2.8.6, supports macOS 10.13 or later), then log out and back in so the session picks it up. Open Terminal and check:
echo $DISPLAY
If it prints a value (with XQuartz it is usually a socket path rather than :0), the client side is ready, and ssh -X user@server works as above. If DISPLAY is empty, start XQuartz once and open a new terminal window. Then use ssh -G server | grep -i forwardx11 to see whether your client uses trusted mode by default. If windows close or new ones are refused after about 20 minutes, that is the untrusted timeout; -Y or a per-host ForwardX11Trusted yes removes it for servers you trust.
If you came here looking for a Mac SSH client with built-in X11, we compared the options in PuTTY alternatives for Mac.
How do you use X11 forwarding from Windows?
The least fiddly path in 2026 is WSL 2. Microsoft's WSLg runs Linux GUI apps (X11 and Wayland) on Windows 10 build 19044+ and Windows 11, after wsl --install or wsl --update. Inside your WSL shell, echo $DISPLAY should already be set. Run ssh -X user@server from WSL, not from PowerShell, and the remote window shows up on your Windows desktop like a local app.
Native Windows options exist too: third-party X servers that you run alongside an SSH client with X11 support. We didn't test them for this article. If you go that way, the same three requirements apply: an X server running, DISPLAY pointing at it, and a server with X11Forwarding yes and xauth.
How do you enable X11 forwarding in ~/.ssh/config?
Set it per host instead of typing -X each time, and avoid putting it under Host *, which would offer your display to every server you log in to:
Host lab-gpu
HostName 10.0.4.21
User alice
ForwardX11 yes
ForwardX11Trusted no
Through a bastion, X11 needs nothing on the jump host. With ProxyJump, the jump host only relays the TCP stream, and the x11-req goes to the final server, so only the target needs X11Forwarding yes and xauth:
Host lab-gpu
ProxyJump bastion
ForwardX11 yes
See our ProxyJump setup guide for the bastion side and ssh config organization tips for keeping per-host options readable.
Is SSH X11 forwarding secure?
The transport is: X11 traffic rides inside the encrypted SSH channel, and the proxy display only listens on the server's loopback by default. The risk is the other direction. The ssh_config(5) man page warns that users who can bypass file permissions on the remote host (root, in practice) can reach your local display through the forwarded connection, and with trusted forwarding that can include keystroke monitoring.
That's the same trust question as agent forwarding, which we covered in SSH agent forwarding security risks. Practical rules:
- Forward X11 only to servers whose admins you'd trust with your screen, and prefer
-Xon shared machines. - Keep
X11UseLocalhost yeson the server. Setting it tonoexposes the proxy display on the network. - On servers that never need GUI programs, set
X11Forwarding no. The sshd_config(5) page notes this does not stop a determined user from building their own forwarder, but it removes the default path. Our SSH security guide covers the rest of a server-side baseline.
When is X11 forwarding the wrong tool?
X11 is a chatty protocol: many operations wait for a reply from your machine, so a modern GUI over a high-latency link feels sluggish, and some apps that render with the GPU won't work well remotely. Before you fight it, check whether one of these fits better:
-
The app has a web UI. Forward its port with
ssh -L 8080:localhost:8080 serverand use your local browser. - You only need the files. Pull them over SFTP and open them in a local program.
- You need a whole desktop or a session that survives disconnects. A VNC or xpra server reached through an SSH tunnel keeps the session alive when your Wi-Fi drops; plain X11 windows die with the SSH connection.
- The program has a CLI or headless mode. Many profilers and installers do, and a headless run is easier to script.
Where does termique fit?
termique doesn't do X11 forwarding. Its documented forwards are local, remote and SOCKS5 ports, and for a lot of "I need a GUI from the server" cases, a port forward to a web UI is the better answer anyway. When you do need X11, run ssh -X from a terminal that has a working DISPLAY as shown above.
Where termique helps is the rest of the work around those servers: saved port forward rules per host that you turn on with a switch (and that reconnect when the connection drops), SFTP for pulling files, and SSH keys and passwords that sync across your devices end-to-end encrypted. termique is a free, native ssh manager we build, with end-to-end encrypted credentials.
FAQ
What is the difference between ssh -X and ssh -Y?
-X requests untrusted forwarding, limited by the X11 SECURITY extension and, by default, a 20-minute cookie lifetime. -Y requests trusted forwarding with full access to your display. On Debian and Ubuntu clients, ForwardX11Trusted defaults to yes, so both behave the same. Check yours with ssh -G host | grep -i forwardx11.
Why does it say "cannot open display" over SSH?
The remote program found no usable DISPLAY. Either forwarding was never set up (empty DISPLAY: start an X server locally and reconnect with -X), the server refused it (X11 forwarding request failed on channel 0), or the cookie is missing for the current user, which is common after sudo.
Do I need X11Forwarding on the jump host?
No. With ProxyJump, only the final server needs X11Forwarding yes and xauth. The jump host just relays the connection.
Does X11 forwarding work with Wayland?
Remote X11 programs still draw on your machine if you run XWayland, which most Wayland desktops include, and WSLg supports both. A program that only speaks Wayland can't use SSH X11 forwarding; it needs a different remoting tool.
Is X11 forwarding enabled by default?
Upstream sshd defaults to X11Forwarding no, but Debian and Ubuntu set X11Forwarding yes in their stock sshd_config. On the client, ForwardX11 defaults to no, so nothing is forwarded until you pass -X or -Y or set it per host.
If you manage a handful of servers and a few port forwards every day, try termique free: saved hosts, saved port forward rules, and credentials end-to-end encrypted across your devices.
Top comments (0)