I see this error a lot:
mawagner ~ $ ssh email@example.com firstname.lastname@example.org'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:
- 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).
- Pop open
/etc/ssh/sshd_config. Make sure that the
X11Forwardingline is set to “yes”. Otherwise, X forwarding will absolutely not work. (You may wish to read the
sshd_configmanpage, as there are some security implications to enabling this—though if you’re reading this, you obviously want to use this feature.)
- Others have reported needing to change
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
X11DisplayOffsetunless 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.)