How to make remote connection (ssh tunnel) with putty/ssh?

17,080

Depends on which setup you want:

SETUP 1) server is listening

                              ssh tunel             LAN destination   
SERVER (listen on port 6000) ==========> LAPTOP -----> ip:port

(LAN destination could also be localhost:port to connect laptop itself)

PUTTY SETUP: right click on putty window title, choose Change settings / Tunnels and fill in:

source port: 6000
destination: ip:port (or hostname:port)
select "Remote"

SSH: ssh -R 6000:hostname:port

SETUP 2) laptop is listening

                              ssh tunel              destination   
LAPTOP (listen on port 7000) ==========> SERVER -----> ip:port

again, the destination could be localhost:port to connect to server itself.

PUTTY setup:

source port: 7000
destination: ip:port (or hostname:port)
select "Local"

SSH: ssh -L 7000:hostname:port

In both cases, you can also specify (in putty by a checkbox) if the listening LAPTOP/SERVER also accepts connection from other hosts.

Share:
17,080

Related videos on Youtube

Glorfindel
Author by

Glorfindel

Life is complex – it has both real and imaginary parts. ♦ moderator on Ask Different (Apple.SE), Chess, English Language Learners, Spanish Language, Stack Apps, Meta Stack Exchange and Board & Card Games. Thanks for your trust! #SOreadytohelp – especially if you want to discuss automation of moderation like repairing broken images or links, or need somebody with shovels to help digging into the dark depths of Stack Exchange (including SEDE and the API). You can ping me in Chat, in Charcoal HQ, the Tavern on the Meta, the Teachers' Lounge or any other room you can find me. Pronouns: Script successfully installed. (If you're wondering what this is about, please check the Pronoun Assistant userscript.)

Updated on September 18, 2022

Comments

  • Glorfindel
    Glorfindel almost 2 years

    I am trying to make a tunnel between a server and laptop with Putty. The problem is, since the laptop has no public IP address, I have to make a reverse connection. But I really don't know how to do that.

    Let me demonstrate what I want:

    SERVER(PORT:6000) ----------> LAPTOP(PORT:7000)

    but since the laptop has no public IP address I have to make like

    SERVER(PORT:6000) <---------- LAPTOP(PORT:7000)

    Can you please tell me what should I write as source port, destination etc.