58

When I do "ssh -X abcserver", I got message "X11 forwarding request failed on channel 0". I checked online and it was suggested to solve it by switching "X11UseLocalhost no" to "X11UseLocalhost yes".

However, both my manager and I don't have this administrative privilege. I am wondering, except this solution, whether there is another option to solve the issue ? I also don't have sudo privilege to directly install X11 on the server.

My local platform is:

Linux version 3.16.0-4-amd64 (debian-kernel@lists.debian.org)
(gcc version 4.8.4 (Debian 4.8.4-1) ) #1 SMP Debian 3.16.7-ckt25-2+deb8u3 (2016-07-02)

The remote platform is:

Linux version 3.13.0-88-generic (buildd@lgw01-16) 
(gcc version 4.8.4 (Ubuntu 4.8.4-2ubuntu1~14.04.3) ) 
#135-Ubuntu SMP Wed Jun 8 21:10:42 UTC 2016
Community
  • 1
  • 1
David Z
  • 6,641
  • 11
  • 50
  • 101
  • 1
    Try `ssh -Y ...`. BTW, your question belongs to a different site of the network. – user3159253 Aug 15 '16 at 19:26
  • Just because you've requested X11 forwarding (normal or trusted) doesn't mean the `sshd` on the other end must allow it. That's one of the first things I'd check. Also `ssh -vv -X` (or `-Y`). – twalberg Aug 19 '16 at 20:23
  • @user3159253: Which site do you think it belongs on? SO has the appropriate tags, and the general question and general answer need not be specific to the OP's platform. – jvriesem Apr 03 '19 at 20:54
  • 1
    looks like a topic for superuser.com or maybe for unix.stackexchange.com – user3159253 Apr 04 '19 at 06:47
  • If you only see this with `git` commands then see solution in https://unix.stackexchange.com/questions/240013/x11-forwarding-request-failed-when-connecting-to-github-com – Axel Bregnsbo Jul 24 '20 at 06:33
  • If you don't have root privileges, fixing a problem with packages and the ssh daemon might be tricky... – rogerdpack Sep 21 '21 at 18:36

6 Answers6

57

Adding the -v option to ssh when trying to log in will give a lot of debug information which might give a clue to exactly what the problem is, like for instance

debug1: Remote: No xauth program; cannot forward with spoofing.

which in my case installing xauth on the server fixed the issue.

hlovdal
  • 26,565
  • 10
  • 94
  • 165
48

I had to edit the sshd config file on the remote server to fix the issue. It worked on Ubuntu 16.04 Server:

$ sudo vim /etc/ssh/sshd_config

Set `X11UseLocalhost no`

Save the file.

$ sudo service sshd restart

$ exit

Now it works!

$ ssh -X user@remotehost  
$ xclock
 
slm
  • 15,396
  • 12
  • 109
  • 124
Keyno
  • 621
  • 5
  • 3
28
  1. sudo apt install xauth
  2. change the line #AddressFamily any to AddressFamily inet in /etc/ssh/sshd_config
  3. sudo service ssh restart

This is enough on Ubuntu 18.04 LTS.

After login with ssh -X (or after activating the PuTTY / KiTTY option "Enable X11 forwarding") you should see that the environment variable DISPLAY is automatically defined to localhost:10.0 or similar. After first successful login (with a functional X11 forwarding) the file .Xauthority will be generated. Another positive sign of success.

If you are interested to see and to understand the details of X11 forwarding within your session you can try with lsof -i -P|grep ssh.

Afsin Toparlak
  • 379
  • 3
  • 4
  • 2
    Thanks this fixed my error in my ssh server logs `sshd[25305]: error: Failed to allocate internet-domain X11 display socket.` – rogerdpack Sep 21 '21 at 18:06
  • 1
    That should be `sudo service sshd restart` or `systemctl restart sshd`, depending on your system. – pacoverflow Apr 12 '22 at 07:59
  • 3
    `AddressFamily inet` fixed it for me. This is needed when IPv6 is disabled. – Alan Sep 28 '22 at 09:42
  • This works for me on Ubuntu 22.04 LTS. @Alan, this all sound incredibly complex for Ubuntu and year 2023. With "all" I mean having to resort to this weird variable to just forward X11. Can you maybe please explain why this is needed when IPv6 is disabled and whether this a change from an older state in which (I think) it worked? – Kiteloopdesign Feb 28 '23 at 00:04
  • @Kiteloopdesign... to be honest I have no idea why it works, but it does. – Alan Mar 01 '23 at 10:35
13

1.make sure that during ssh -X root@server you have root permission.

2.update the /etc/ssh/sshd_config and make sure this line is uncommented

    X11Forwarding yes

3.systemctl restart sshd

4.exit from server

5.ssh -X root@server

6.virt-manager

HugoTeixeira
  • 4,674
  • 3
  • 22
  • 32
Marie
  • 141
  • 2
1

In my case, as superuser, editing /etc/ssh/sshd_config on the remote host and changing the following line fixed it.

From

#X11Forwarding no

to

X11Forwarding yes

Then: pkill -HUP sshd on the remote host to make sshd reload its config, which also closes the sshd session.

clearlight
  • 12,255
  • 11
  • 57
  • 75
1

After X11 forwarding suddenly stopped working after no other changes than connecting the ssh server to another wifi, I followed the answer to this seemingly completely different question and it worked.

In other words, it seems the solution for me was to specify AddressFamily inet in /etc/ssh/sshd_config.

sampi
  • 576
  • 5
  • 15