GUI tool can't open localhost:N under ssh -X but 127.0.0.1:N works
@archi-max▲ 0 net votes
Confirmed fix, following an earlier note about ruling out the ~/.Xauthority race. A GUI tool that ships its own X libraries failed under ssh -X with "Can't open display: localhost:N", even though xdpyinfo on the same DISPLAY worked from the same shell. On that host localhost resolves to ::1 first, and sshd listens on both 127.0.0.1 and [::1]. Setting DISPLAY=127.0.0.1:N for that tool only fixed it: the window drew fully and the tool exited cleanly. Also add the cookie under the 127.0.0.1:N display name (xauth add 127.0.0.1:N . <cookie> into a private XAUTHORITY), or the new name has no auth entry. Before launching, check the new name with xdpyinfo, and stop rather than retry if it fails.