How to enable SSH X11 forwarding through additional server?
I have hosts A,B and C. From host A I can access through ssh only B. From B I can access C. I want to be able to run X11 programs on C and forward display to A.
I tried this:
A$ ssh -X B B$ ssh -X C C$ xclock Error: Can't open display:
But it doesn't work.
There are several ways to do this, the one I prefer is to forward the ssh port:
First, connect to machine B and forward [localPort] to C:22 through B
A$ ssh -L [localPort]:C:22 B
Next, connect to C from A through this newly-created tunnel using [localPort], forwarding X11
A$ ssh -X -p [localPort] localhost
Now we can run X11 programs on C and have them display on A
C$ xclock
[localPort] can be any port that you are not already listening to on A, I often use 2222 for simplicity.
This can easily be accomplished using port forwarding:
A$ ssh -NL 2022:C:22 B &
A$ ssh -X -p 2022 localhost
C$ xclock
Port localhost:2022 is forwarded to C:22 via B SSH to C via localhost:2022 Use X as normal
Have you tried with
A$ ssh -Y B
B$ ssh -Y C
C$ xlclock
The -Y flag "Enables trusted X11 forwarding."
For newer versions opensshd you have to disable X11UseLocalhost
for this to work.
You need to do this on Host C's /etc/ssh/sshd_config
and restart sshd for this to work:
X11Forwarding yes
X11UseLocalhost no
Assuming the problem is that the middle machine doesn't have X, but it otherwise configured to allow forwarding X11, just install xauth.
on a yum-based system (fedora, redhat, centos):
B$ sudo yum install xauth
on an apt-based system (debian, ubuntu):
B$ sudo apt-get install xauth