How to fix “X11 forwarding request failed on channel 0”

Question: When I tried to SSH to a remote host with X11 forwarding option, I got "X11 forwarding request failed on channel 0" error after logging in. Why am I getting this error, and how can I fix this problem?

First of all, we assume that you already enabled X11 forwarding over SSH properly.

If you are getting "X11 forwarding request failed on channel 0" message upon SSH login, there could be several reasons. Solutions vary as well.

Solution One

For security reason, OpenSSH server, by default, binds X11 forwarding server to the local loopback address, and sets the hostname in DISPLAY environment variable to "localhost". Under this setup, some X11 clients cannot handle X11 forwarding properly, which causes the reported error. To fix this problem, add the following line in /etc/ssh/sshd_config file, which will let X11 forwarding server bind on the wild card address.

$ sudo vi /etc/ssh/sshd_config
X11Forwarding yes
X11UseLocalhost no

Restart SSH server to activate the change:

$ sudo /etc/init.d/ssh restart (Debian 6, Ubuntu or Linux Mint)
$ sudo systemctl restart ssh.service (Debian 7, CentOS/RHEL 7, Fedora)
$ sudo service sshd restart (CentOS/RHEL 6)

Solution Two

The broken X11 forwarding error may also happen if the remote host where SSH server is running has IPv6 disabled. To fix the error in this case, open /etc/ssh/sshd_config file, and uncomment "AddressFamily all" (if any). Then add the following line. This will force SSH server to use IPv4 only, but not IPv6.

$ sudo vi /etc/ssh/sshd_config
AddressFamily inet

Again, restart SSH server to finalize the change.

Download this article as ad-free PDF (made possible by your kind donation): 
Download PDF

Subscribe to Ask Xmodulo

Do you want to receive Linux related questions & answers published at Ask Xmodulo? Enter your email address below, and we will deliver our Linux Q&A straight to your email box, for free. Delivery powered by Google Feedburner.


Support Xmodulo

Did you find this tutorial helpful? Then please be generous and support Xmodulo!

9 thoughts on “How to fix “X11 forwarding request failed on channel 0”

  1. >> The broken X11 forwarding error may also happen if the remote host where SSH server is running has IPv6 disabled.

    Ah ha!

    Thank you!

    • This is the problem I had. This was with a new clean install of Centos 7 with the default software selection

  2. In my case, the problem was in /etc/ssh/ssh_config
    ForwardX11 no
    ForwardX11 yes
    was uncommented.

    commenting it
    # ForwardX11 no
    # ForwardX11 yes
    and restarting ssh fixed the problem.

  3. Nothing on here worked for me, but finally after finding a reference somewhere else I found my problem.

    It appears that the sshd program I had on my CentOS 6.5 system was hardcoded to look for xauth in /usr/X11R6/bin/xauth if not specifically mentioned in the config file. However, the xauth program was actually located in /usr/bin/xauth. This all worked fine on an older Centos 5.3 machine (sshd looked in /usr/bin/xauth by default).

    I saw that one person solved this by creating a symbolic link, but I think the preferred solution is to add the following line to /etc/ssh/sshd_config to tell it where xauth is:

    XAuthLocation /usr/bin/xauth

    My default sshd_config file did not even have a placeholder (i.e. commented out line) for this variable

    After inserting the line telling where xauth was located and restarting sshd, it finally worked.

Leave a comment

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