X Window System
Sources:
- X Window 配置介绍
X Window System
The X Window System (X11) is a windowing protocol (and system design) used on Unix-like systems. It allows you to run a graphical application on one machine while displaying it on another. To do this, it splits the GUI into two roles:
- X server: runs where your display and keyboard/mouse are; it renders windows and handles input.
- X client: a GUI application that connects to an X server via the X11 protocol.
In practice, “run a GUI app remotely, display it locally” means running an X client on the remote host and having it connect to your local X server (usually your laptop).
X11 forwarding over SSH
SSH suuports X11 forwarding by tunneling X11 traffic through the SSH connection so that remote X clients show up as local windows:
- sshd allocates a forwarded display on the remote side (e.g. DISPLAY=localhost:10.0).
- Remote GUI apps connect to that display.
- X11 messages are forwarded over the encrypted SSH channel.
- Your local X server renders the windows and handles input.
Local + remote checklist
Local machine (where windows should appear):
Ensure an X server exists and is running:
- macOS: XQuartz
- Windows: Xming / VcXsrv
- Linux desktop: usually already available (Xorg / Xwayland)
Remote host:
sshd allows forwarding (/etc/ssh/sshd_config):
1 | X11Forwarding yes |
Then restart:
1 | sudo systemctl restart sshd |
Install at least one small X client for testing, e.g. xclock / xeyes / xterm.
Usage + quick test
Connect with forwarding:
- -X: untrusted (safer, more restrictions; some apps break)
- -Y: trusted (works more often; only for hosts you trust)
1 | ssh -X username@remotehost |
Then on the remote host:
1 | echo "$DISPLAY" # expect localhost:10.0 (or similar) |
DISPLAY
The DISPLAY environment variable tells an X client where to find the X server. Its common forms are:
:0
The “local” X server on the same machine (display number 0). This is what you usually see in a normal desktop session.hostname:N.M(e.g.localhost:10.0)
Connect to an X server via a network endpoint.Nis the display number, and.Mis the screen number (almost always0).
For example, with SSH X11 forwarding, sshd sets DISPLAY on the remote host to something like localhost:10.0. This does not mean “use your laptop’s X server directly at localhost”. It means:
- on the remote machine, X clients connect to a local loopback listener owned by
sshd(thelocalhost:10.0endpoint), - and
sshdforwards the X11 protocol over the SSH channel to the real X server on your local machine.
macOS caveat (XQuartz + OpenGL/GLX)
XQuartz can be unreliable for OpenGL/GLX over X11 forwarding. GLX-heavy apps (e.g. glxgears) may show static windows or fail.
Sometimes forcing indirect rendering helps:
1 | export LIBGL_ALWAYS_INDIRECT=1 |
If you need usable remote graphics on macOS, prefer VNC (full remote desktop) or xpra (per-app remoting) over raw X11 forwarding.