4

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”?

2 Answers 2

3

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
  • +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!!). Apr 29, 2017 at 7:42
2

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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .