32

I'm able to login to the server using:

ssh -X Hostip

but when I run the command xclock it gives me this error:

Error: Can't open display: localhost:11.0

I checked my display value using:

echo $DISPLAY

and the result is:

localhost:11.0

And X11 forwarding is set to YES in sshd_config file:

X11Forwarding yes
X11DisplayOffset 10
X11UseLocalhost yes

Do you have any advice what I'm missing here?

karel
  • 2,030
OmiPenguin
  • 4,308
  • 3
    Have you tried -Y instead of -X? – Flup Jul 22 '13 at 11:35
  • 2
    Also, make sure you understand the implications of using -Y instead of -X. You may also want to look at xhost. – user Jul 22 '13 at 11:36
  • 1
    For RedHat/CentOS 7 (at least), you need the xorg-x11-xauth package, as per my answer here: http://unix.stackexchange.com/questions/138936/why-wont-x11-display-work-through-ssh-login/212952#212952 – Mike S Apr 22 '16 at 20:12

7 Answers7

24

Use -Y. From the man page on ssh:

-Y Enables trusted X11 forwarding. Trusted X11 forwardings are not subjected to the X11 SECURITY extension controls.

If you're still having problems though, you can try setting $DISPLAY to your local box's IP:

$ export DISPLAY='<ip_address>:11.0'

It may work to set it as

$ export DISPLAY='127.0.0.1:11.0'

People seem to have this problem commonly when ssh'ing from Mac OS X. You may also want to set

X11UseLocalhost no

in this case as well.

  • 1
    Using XQuartz I was unable to use the -Y flag.

    "X11 connection rejected because of wrong authentication."

    – Erik Feb 21 '14 at 04:01
  • 6
    even after trying your other suggestions, I'm unable to open a display. – Erik Feb 21 '14 at 04:04
  • 2
    Neither one of these worked for me either. I needed to install XWindow support in my Centos 7 server (minimal) with: yum groupinstall "X Window System" -y – Mark Edington Dec 29 '15 at 16:19
  • @MarkEdington this is because RedHat/CentOS require the xorg-x11-xauth package, as per my answer here: http://unix.stackexchange.com/questions/138936/why-wont-x11-display-work-through-ssh-login/212952#212952 – Mike S Apr 22 '16 at 20:11
10

this worked for me:

Change

X11UseLocalhost yes

to

X11UseLocalhost no
Anthon
  • 79,293
don
  • 101
9

Credit to https://unix.stackexchange.com/a/12772/61349 for their diagnostic instructions.

Ensure you're ssh client is requesting X11 Forwarding with the -v flag

ssh example.com -X -v

And look for thespecific message:

debug1: Requesting X11 forwarding with authentication spoofing.

Another telltail problem sign is the lack of the DISPLAY environment variable beign set for you. If its blank/unset, there is something wrong. At least according to the same post credited above, these variables are set for you automatically.


I was using an SSH Control Master my ssh connections like so:

Host <hostname>
    ControlMaster auto
    ControlPath ~/.ssh/control/%r@%h:%p
    ControlPersist 10m

My earlier ssh connection did not request X11Firwarding, therefore future ssh call's options weren't being used. So for me,

ssh -X was just being ignored altogether

If you aren't seeing "Requesting X11 Forwarding", but you do see the muxer reusing sessions;

debug1: auto-mux: Trying existing master
debug1: mux_client_request_session: master session id: 10

Then you need to exit your current ControlMaster for that connection and reconnect with the -X/-Y flag.

To Stop your ControlMaster

ssh -O check <hostname>

Master running (pid=2758)

(This will exit all active connections using the ControlMaster)

ssh -O exit <hostname>

Exit request sent.
ThorSummoner
  • 4,422
  • what should I do if I see debug1: Requesting X11 forwarding with authentication spoofing then? – Esther May 09 '22 at 18:18
5

What fixed this for me is simply installing xauth, once done it worked like a charm!

Mostafa
  • 51
4

When trying to forward to XQuartz on macOS, I fixed the issue by running the ssh command (ssh -Y in my case) from the XQuartz terminal (opened by right-clicking the XQuartz icon in the dock and clicking Applications > Terminal).

Harry Cutts
  • 242
  • 1
  • 10
0

Problem got fixed by installing "x11-server-utils" and reloading both sshd and my ssh session.

0

I faced similar problem - i was working on a remote server where i had to work with interactive plots and none of the above mentioned solutions worked for me.

I was using Ubuntu bash on Windows 10 and in the end installing Xming software (http://www.straightrunning.com/XmingNotes/) on Windows. There might be some configurations needed but I was finally able to work with plots on remote server. Just install and launch it (you can see its icon on the bottom tray), and run your graphical application again on the remote server (using the ssh session). Hope it helps!

  • As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers in the help center. – Community Feb 13 '22 at 20:32