Running X11 applications over SSH
The program runs on the remote machine, but its windows open on your screen. Three things make that work: forwarding enabled on the server, an X server on your own machine, and the -X or -Y flag when you connect.
1Configure the server
On the machine you SSH into, edit /etc/ssh/sshd_config and make sure these lines are present and not commented out:
X11Forwarding yes
X11DisplayOffset 10
X11UseLocalhost yesThe server also needs xauth, which SSH uses to set up the authentication cookie:
sudo apt install xauth # Debian/Ubuntu
sudo dnf install xorg-x11-xauth # Fedora/RHELThen restart the SSH daemon:
sudo systemctl restart sshd # or "ssh" on Debian/Ubuntu2Run an X server locally
Pick your local operating system:
Nothing to install if you're in a desktop session. Both X11 and Wayland (through XWayland) work.
Install XQuartz, then log out and back in so the DISPLAY setup takes effect.
Use MobaXterm, which has an X server built in. Alternatively, run VcXsrv or Xming alongside OpenSSH or PuTTY; in PuTTY, enable Connection → SSH → X11 → Enable X11 forwarding. On Windows 11, WSLg also works from inside WSL.
3Connect with forwarding
ssh -X user@host # untrusted forwarding (more restricted)
ssh -Y user@host # trusted forwarding (fewer issues, less secure)To make it permanent for a host, add this to ~/.ssh/config:
Host myserver
HostName host.example.com
User user
ForwardX11 yes
ForwardX11Trusted yes4Test it
echo $DISPLAY # should show something like localhost:10.0
xclock # or xeyes; install x11-apps if missingIf a clock window appears on your screen, forwarding works.
Troubleshooting
$DISPLAYis empty- The server isn’t forwarding. Recheck
sshd_config, confirmxauthis installed, and connect withssh -v -Xto look for “X11 forwarding request failed.” - “cannot open display”
- Your local X server probably isn’t running. This is common on macOS and Windows.
- Apps crash with
-Xbut work with-Y - Untrusted mode blocks some X extensions. Use
-Yfor hosts you trust. - Forwarding fails on servers with IPv4 disabled
- Adding
AddressFamily inettosshd_configsometimes fixes it.
Performance
X11 forwarding can be sluggish for heavy GUI apps over slow links. Compression helps a little:
ssh -X -C user@hostFor noticeably better responsiveness, use VNC, X2Go, or xpra instead.