why won't x11 display work through ssh login?
I just ran into this problem connecting to a headless RHEL7 server.
You need the xorg-x11-xauth package installed on your host in order for the DISPLAY variable to get set, and to be properly authorized.
Hope I saved somebody some time.
Make sure that you have the DISPLAY-variable set in your cygwin-environment:
export DISPLAY=:0.0
after connecting with SSH, check if that shell also knows the correct DISPLAY-variable with:
echo $DISPLAY
Thanks to @jensd, @unxnut for helping me. based on your comments I was able to figure out the problem.
The solution needed two steps:
- the DISPLAY variable should be properly set.
- when ssh'ing to remote server, the -X switch must be on
my previous attempts lack one or both of these two conditions.
Anyhow, for later users who see this here's are examples to show you what I'm trying to say.
case1
my local machine will have no DISPLAY variable set. And then I will ssh to remote server with -X switch and then try executing xclock
.
Black@Black-PC ~
$ echo $DISPLAY
## the blank means that DISPLAY variable has not been specified##
Black@Black-PC ~
$ ssh -X kwagjj@$labserver -p 122
Last login: Tue Jun 24 22:23:13 2014 from
[kwagjj@James5 ~]$ xclock
Error: Can't open display:
[kwagjj@James5 ~]$ setenv | grep $DISPLAY
DISPLAY: Undefined variable.
as you can see an error Error: Can't open display:
is shown at the remote server terminal.
case2
this time, at the local machine, I will specify the DISPLAY variable. But when I'm ssh'ing, I won't turn on the -X switch. The result will be a failure:
Black@Black-PC ~
$ export DISPLAY=:0.0
Black@Black-PC ~
$ echo $DISPLAY
:0.0
Black@Black-PC ~
$ ssh kwagjj@$labserver -p 122
Last login: Tue Jun 24 22:33:32 2014 from
[kwagjj@James5 ~]$ xclock
Error: Can't open display:
[kwagjj@James5 ~]$ setenv | grep DISPLAY
[kwagjj@James5 ~]$
at the start you can see that I have properly set the DISPLAY variable. But even so, after ssh'ing(without the -X switch) the xclock is not executed.
*A different outcome with setenv | grep DISPLAY
can be seen here(compare with case1). in case2, the result is just blank. on the other hand, the result of case1 to this command line is DISPLAY: undefined variable
.... I'm not sure how this difference is caused but I'm getting a hunch that its related to whether you've satisfied either condition 1. or 2.
case3
this time, I will properly specify the DISPLAY variable at the local machine and also ssh to remote server with my -X switch on.
Black@Black-PC ~
$ echo $DISPLAY
:0.0
Black@Black-PC ~
$ ssh -X kwagjj@$labserver -p 122
Warning: untrusted X11 forwarding setup failed: xauth key data not generated
Warning: No xauth data; using fake authentication data for X11 forwarding.
Last login: Tue Jun 24 22:37:27 2014 from
[kwagjj@James5 ~]$ xclock &
[1] 9174
[kwagjj@James5 ~]$ setenv | grep DISPLAY
DISPLAY=localhost:11.0
[kwagjj@James5 ~]$
with this setting, xclock
works!! here's a screenshot to prove that I'm not lying.
the xclock is successfully shown in my local machine.
Again, check out the result of setenv | grep DISPLAY
in this case. It now shows DISPLAY=localhost:11.0
. From what I know, this is related with MIT-MAGIC-COOKIE in the .Xauthority file but since I don't know much about this I won't go any further.
Conclusion: from the three cases above, we can confirm that in order for remote X Windows to be displayed properly, both 1. DISPLAY variable of local machine and 2. ssh -X
switch must be properly set. Of course, the remote server should allow X11forwarding.