SSH "X11 forwarding request failed on channel 0" and "cannot open display" with ssh -X
The host refused X11 forwarding: X11Forwarding is off, xauth is missing, or no display port was free. ssh -v shows which. No local DISPLAY, no request.
With ssh -X (or -Y, or ForwardX11 yes in ~/.ssh/config), ssh asks the host to forward X11, so that graphical programs started on the host open their windows on your screen. If the host says no, ssh prints:
X11 forwarding request failed on channel 0
The login still works, but DISPLAY is empty on the host, so a graphical program fails with a message such as "cannot open display".
Find the reason with ssh -v
The host sends the reason as a debug message, which ssh shows only in verbose mode:
ssh -v -X [email protected]
Look for a line that starts with debug1: Remote: just before the failure:
No xauth program; cannot forward X11.sshd could not find thexauthprogram at itsXAuthLocation(the manual gives/usr/X11R6/bin/xauth; Debian and Ubuntu builds use/usr/bin/xauth). Install the distribution'sxauthpackage on the host, or pointXAuthLocationinsshd_configto wherexauthreally is.X11 forwarding disabled by key options.Your key in~/.ssh/authorized_keyshasno-X11-forwardingorrestrictin front of it.- No
Remote:line at all. sshd's own setting is off:X11Forwardingdefaults tono, andDisableForwarding yesturns it off too. sshd logs this only in its own debug output.
After changing sshd_config, check it with sshd -t and restart the SSH service. The change applies to new connections.
sshd could not open a display
With X11Forwarding yes and xauth in place, sshd still has to listen on a display port. It tries display numbers from X11DisplayOffset (default 10) upward; when none works, sshd logs:
Failed to allocate internet-domain X11 display socket.
sshd opens a socket for each address family it uses, and a display number is skipped if any of them fails. If IPv6 is turned off on the host, setting AddressFamily inet in sshd_config limits sshd to IPv4, so it no longer tries the IPv6 address.
Nothing happens and there is no error
If DISPLAY is not set where you run ssh, there is no local X server to forward to. ssh then does not send an X11 request at all and says so only with -v:
debug1: X11 forwarding requested but DISPLAY not set
X11 forwarding needs an X server on your side. If the device or terminal you connect from has none, there is nothing to show the windows on.
-X or -Y
-X forwards as an untrusted client, limited by the X11 SECURITY extension. -Y forwards as trusted, without those limits. The ssh and ssh_config manuals explain what each one lets remote programs do with your display.
Related
- SSH error messages, what each one means
- Port forwarding: local, remote, dynamic
- SSH ControlMaster: reuse one connection with ControlPath and ControlPersist
- Authorized keys and permissions
- How Mosh works
Sources
- sshd_config(5): X11Forwarding, X11DisplayOffset, X11UseLocalhost, XAuthLocation, AddressFamily, DisableForwarding
- ssh(1): -X, -x and -Y
- ssh_config(5): ForwardX11, ForwardX11Trusted, XAuthLocation
- sshd(8): no-X11-forwarding and restrict
- OpenSSH source: session.c, the reasons sshd sends
- OpenSSH source: channels.c, the display socket
- OpenSSH source: ssh.c, DISPLAY not set