Fixing X11 forwarding request failed on channel 0

I see this error a lot:

mawagner ~ $ ssh root@mawagner-cs24.usersys.redhat.com
root@mawagner-cs24.usersys.redhat.com's password:
X11 forwarding request failed on channel 0

There are a lot of forum posts about people having this problem, but surprisingly few questions that give a good answer. It just took me forever to run down what was causing it for me.

This gist is the closest I’ve seen to a big-picture look at what’s going on, but it still didn’t directly solve my problem. My solution came here (French). But the short version is this: that error can be caused by a lot of things.

Here’s a list of things I would check, in order of ease:

  1. ssh’ed into the remote machine, is an “xauth” command available for you to run? You don’t even have to run it, but does it exist? This was my problem, and it was fixed with yum install xorg-x11-xauth (or the equivalent for non-yum systems).
  2. Pop open /etc/ssh/sshd_config. Make sure that the X11Forwarding line is set to “yes”. Otherwise, X forwarding will absolutely not work. (You may wish to read the sshd_config manpage, as there are some security implications to enabling this—though if you’re reading this, you obviously want to use this feature.)
  3. Others have reported needing to change X11UseLocalhost to no, but I haven’t found this to be necessary. The man page suggests that this is only needed for “some older X11 clients”. Most of the posts I’ve seen about this setting seem to involve people changing settings randomly hoping to hit on a working solution, so don’t change this or X11DisplayOffset unless nothing else works.

Remember that after changing sshd_config, you must service restart sshd. This should not impact existing sessions. (But I always open a new tab in my terminal and test login there before logging out of the existing session, to make sure sshd came up cleanly so I don’t accidentally lock myself out.)

Another recommendation (which I totally missed until I had solved the issue) was to add the -v flag when starting your ssh session, to enable verbose logging. This might indicate the problem.

If none of the above solves your problem, this page (also linked above) was very helpful. Hopefully this post will help someone, though. (Please note that I am by no means an expert on getting X11 forwarding working with X. I just happen to have fixed it in my case and wanted to write up what I did, for my future self or for others.)

Leave a Reply

Your email address will not be published. Required fields are marked *

To create code blocks or other preformatted text, indent by four spaces:

    This will be displayed in a monospaced font. The first four 
    spaces will be stripped off, but all other whitespace
    will be preserved.
    
    Markdown is turned off in code blocks:
     [This is not a link](http://example.com)

To create not a block, but an inline code span, use backticks:

Here is some inline `code`.

For more help see http://daringfireball.net/projects/markdown/syntax