X / X11 forwarding over SSH - an alternative to remote desktop
The usual way to run remote systems graphically is through some kind of remote desktop service. Like VNC or remote desktop (RDP). An alternative way is X forwarding which forwards remote application windows over SSH and displays them on the local system. Example, with one Linux client and one Linux host: Host: /etc/ssh/sshd_config must contain X11Forwarding yes or add a file to /etc/ssh/sshd_config.d/forwarding.conf and put it into it - note that it must end with .conf: X11Forwarding yes xauth must be installed - apt-get install xauth Client: ~/.ssh/config. should contain: Compression yes ForwardX11 yes How to use: Login to the host as usual using SSH, for example: ssh examplehost -l username Add -X if you haven't added X11Forwarding yes to your local config file: ssh examplehost -X -l username Then run a desktop application, like mate-terminal on the host. The program will pop up on your local machine if everything works as expected. You may even start a full desktop session. For example, in MATE you run mate-session. Add -C for compression.
Multiple hosts and compression
To use multiple hosts and compression on some, do this in the config file: Host example.com Compression yes ForwardX11 yes Host * ForwardX11 no
Troubleshooting - Gtk-WARNING **: cannot open display: / X11 forwarding request failed on channel 0
The X11 forwarding server listens on port 6000+, like 6010, 6020 and so on. SSH(D) first tries IPv6 and then should fall back to IPv4. But if this fails then it cannot connect.
On the server, check if the IPv6 loopback interface is missing by running ifconfig
Example, a system with an IPv6 loopback interface:
lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536
inet 127.0.0.1 netmask 255.0.0.0
inet6 ::1 prefixlen 128 scopeid 0x10<host>
loop txqueuelen 1000 (Local Loopback
...
Example, a system without it:
lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536
inet 127.0.0.1 netmask 255.0.0.0
loop txqueuelen 1000 (Local Loopback)
...
Option 1, enable IPv6:
To enable, check this page: https://bobcares.com/blog/debian-12-disable-ipv6/
In short, check for status and properties:
cat /proc/sys/net/ipv6/conf/all/disable_ipv6
sudo sysctl net.ipv6.conf.all.disable_ipv6
sudo sysctl net.ipv6.conf.default.disable_ipv6
If you get 0 then IPv6 is enabled, if 0 then it is disabled. To enable until next reboot:
sudo sysctl -w net.ipv6.conf.all.disable_ipv6=1
sudo sysctl -w net.ipv6.conf.default.disable_ipv6=1
To keep the settings after reboot, check /etc/systctl.d for files like 70-disable-ipv6.conf that contains net.ipv6.conf.all.disable_ipv6 = 1 and remove the lines or files.
Option 2, add to sshd_config to limit the SSHD server to IPv4 only:
AddressFamily inet
Option 3, allow the SSHD X11 forwarding server to listen to all network interfaces and not only localhost:
X11UseLocalhost no
References:
https://unix.stackexchange.com/questions/12755/how-to-forward-x-over-ssh-to-run-graphics-applications-remotely
https://ubuntuforums.org/showthread.php?t=1504404
https://www.cyberciti.biz/faq/how-to-fix-x11-forwarding-request-failed-on-channel-0/
https://unix.stackexchange.com/questions/470905/why-addressfamily-needs-to-be-configured-for-x11-forwarding
https://support.oracle.com/knowledge/Sun%20Microsystems/3007988_1.html
This is a personal note. Last updated: 2025-11-03 16:36:50.



