Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SSH two computers behind firewalls through external server

Tags:

ssh-tunnel

I own two computers at a University. Both of them are behind some sort of firewall etc. which disallows me to directly connect them over the network. They can both SSH public computers, but I can't figure out how to ssh from one to the other. I also run a small website. My question is, can I use the public address of my website to somehow connect my two computers without all the information flowing through my website and eating all my bandwidth? Ideally I'd like to create a ssh tunnel between my two computers.

I've already tried Hamachi, it doesn't play well with macs anymore and I'd like more control over the connection.

like image 298
Evan Avatar asked Feb 18 '11 18:02

Evan


People also ask

Is SSH a two way connection?

With Two-Way SSH tunnel you can connect to any destination under a single condition, which is, the ability to ssh login from the destination to the source. If you can do that, you can as well reverse login from source to destination even if it is behind firewall or NAT.

Can you SSH into a computer on a different network?

Yes, it is absolutely possible. You typically use port forwarding for that (for different residential routers, the way you do port forwarding may vary).

Can you SSH between two Windows machines?

You can "ssh into" a Windows 10 machine from Linux or other Windows machines. For me personally this kind of connectivity is essential. I may be using 3 or 4 different machine at the same time and I always have several terminal's open. I typically work with Linux and Windows 10 (locally or remotely) at the same time.


1 Answers

Let's assume you want to ssh from MachineA to MachineB (both at the university) by going through your ServerC (your public server).

You will need to run sshd on the ServerC and on MachineB.

Run the following commands, assuming your sshd is listening on port 22 on MachineB and ServerC :

# Forward incoming connections from ServerC:22000 to MachineB:22
(on MachineB) ssh -R22000:127.0.0.1:22 -N user@ServerC
# Forward incoming connections from 127.0.0.1:22000 to ServerC:22000
(on MachineA) ssh -L22000:127.0.0.1:22000 -N user@ServerC
# Establish the link between MachineA and MachineB
(on MachineA) ssh -p 22000 [email protected]

This method only needs access to the port 22, and you can easily change this to 80 or 443 if your university proxy is evil.

like image 103
Artefact2 Avatar answered Nov 13 '22 10:11

Artefact2