I need to connect via ssh to a computer “C” that can only be accessed through a frontdoor server “B”. I can do this either by setting ProxyCommand in the config file or by:

ssh -t user@B ssh user@C

In the computer “C” X11 forwarding is on, but on the server “B” it is off, and I am not the admin/root.

Is there a way to connect “A” to “C” (through “B”) with X11 forwarding even if it is off in “B”?


A ssh tunnel would solve this by giving a "direct" route from your computer to server C - but you need to be able to log in to serverB...

user@serverA:~/ $ ssh -L2222:serverC:22 user@serverB

Log in as normal, open a new terminal and

user@serverA:~/ $ ssh -p 2222 serverCusername@localhost

When you connect to port 2222 on your localhost (ie, serverA) your connection goes across your SSH connection to serverB, at which point it opens a new random high port on serverB and reaches out as a new connection, originating from serverB and attempts to connect to serverC

On the first ssh command, when you reference serverC use whatever name/ip that serverB sees it as/can resolve/can connect to

  • +1 from me, the port forwarding form you used is seldom mentioned on these pages, even though it is very useful (as in this case!!). – MariusMatutiae Apr 29 '17 at 7:42

You obviously can connect using a proxy with this method, but the prefferred way is to set that up using ProxyJump or -J switch, which will result into authenticating you from your computer and not the middle one and will not limit any of the functionality provided by SSH (port forwarding, X11 forwarding, ...). You can achieve the same using

ssh -J user@B user@C

Which can be also written in the configuration file as

Host C
  User user
  ProxyJump user@B

Or if you have older OpenSSH version, using ProxyCommand:

Host C
  User user
  ProxyCommand ssh -W %H:%p user@B

and then connect just with ssh -Y C

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.