How to use X11 forwarding over SSH

Run ssh -X user@server, then start a graphical program such as xeyes. Its window opens on your screen. The server needs X11Forwarding yes in sshd_config and xauth installed, and your machine needs a running X server, which on a Mac means XQuartz. -Y gives the program full access to your display, so use it only with servers you trust.

Updated . OpenSSH 10.0 client and server on Debian 13 in throwaway containers, with Xvfb as the display and xeyes, xdpyinfo and xwd as programs.

Set up the server

Install xauth, plus a small program to test with:

sudo apt install xauth x11-apps

In /etc/ssh/sshd_config, set:

X11Forwarding yes

The OpenSSH default is no, although the configuration file on Debian sets it to yes. Reload after a change:

sudo sshd -t && sudo systemctl reload ssh

The service is called sshd on some systems.

Connect and test

ssh -X user@server
echo $DISPLAY
xeyes

DISPLAY should look like localhost:10.0. That is the proxy that sshd creates on the server, not your real display. Do not set DISPLAY by hand.

To make it permanent for one server, use ~/.ssh/config:

Host server
  ForwardX11 yes

-X or -Y

-X, untrusted-Y, trusted
Access to your displayLimited by the X11 SECURITY extensionFull
Screenshot of the whole display with xwd -rootFailed: unable to get imageWorked
Other window's properties with xpropWorkedWorked
Time limitNew windows refused after 20 minutesNone

Untrusted is the upstream default for -X. These results come from our test on Xvfb with X authentication on. Without authentication, -X limited nothing. So -X reduces what a program can reach, but it does not isolate it. Some programs lose features in this mode: xeyes printed extension "XInputExtension" missing and still opened.

If windows stop opening after 20 minutes under -X, with Can't open display, raise the limit in ~/.ssh/config, for example ForwardX11Timeout 8h.

On Debian and Ubuntu, -X behaves like -Y

Debian's client sets ForwardX11Trusted yes by default, so -X is trusted there. In our test ssh -G showed yes on Debian 13 and no on macOS. For the stricter mode on Debian, add -o ForwardX11Trusted=no, which is how we ran the untrusted test. See what your client does with:

ssh -G server | grep -i forwardx11

The security risk

With trusted forwarding, a program on the server can capture your screen and read keys you type in other windows. So can anyone who can get past file permissions on the server, such as root, because they can reach the same forwarded display. Do not forward X11 to a server you do not trust. Use -Y only when a program fails with -X.

Forwarding your SSH agent carries a similar risk for your keys: see SSH agent forwarding risks.

On a Mac: XQuartz

macOS has no X server. Install XQuartz, then log out and back in so that DISPLAY gets set in your session. On Debian we confirmed what happens with an empty DISPLAY: if echo $DISPLAY is empty, ssh -X connects without forwarding and without any visible error. Only ssh -v tells you X11 forwarding requested but DISPLAY not set.

The macOS client looks for xauth at /usr/X11R6/bin/xauth by default. If it complains, point it at the one from XQuartz, which normally installs under /opt/X11, in ~/.ssh/config:

Host *
  XAuthLocation /opt/X11/bin/xauth

Errors

MessageCauseCheck
X11 forwarding request failed on channel 0X11Forwarding no on the server, or no xauth there. We got this for bothsudo sshd -T | grep -i x11forwarding and which xauth
Error: Can't open display: with nothing after itDISPLAY is empty, so forwarding is offecho $DISPLAY on both sides, and ssh -v
Warning: untrusted X11 forwarding setup failed: xauth key data not generatedNo xauth on your machinewhich xauth, then set XAuthLocation

Questions

What is the difference between ssh -X and ssh -Y?

-X is untrusted forwarding, limited by the X11 SECURITY extension. -Y is trusted and gives the program full access to your display. On Debian and Ubuntu, -X is trusted by default.

Why does ssh -X connect but no window opens?

Forwarding did not start. Either DISPLAY is empty on your machine, or the server has X11Forwarding no or no xauth. ssh -v shows which.

Do I need XQuartz on a Mac?

Yes. macOS has no X server. Install XQuartz, then log out and back in before you use ssh -X.

Does X11 forwarding work on Wayland?

Yes, through XWayland, which most Wayland desktops run. If echo $DISPLAY shows a value such as :0 on your machine, ssh -X works as usual and the programs open as X11 windows.

Why is X11 forwarding so slow?

X11 makes many round trips between the program and your screen, so network latency matters more than bandwidth. ssh -C compresses the traffic, which helps on slow links. For a whole desktop over the internet, VNC or RDP through an SSH tunnel is usually smoother.

Sources

More in Sessions and tmux

All guides