SSH Port Forwarding

One-liner explanations + exact commands. No fluff. Just pivot and go.

Quick Decision Table

Situation

SSH Direction

Target Known?

Proxy Needed?

Use

Flag

You can SSH into a box and access a known internal host

SSH into victim

βœ… Yes

❌ No

Local Port Forwarding

-L

You have reverse shell and want Kali to access an internal host via victim

SSH from victim to Kali

βœ… Yes

❌ No

Remote Port Forwarding

-R

You can SSH into a box and want to scan multiple unknown targets

SSH into victim

❌ No

βœ… Yes

Dynamic Port Forwarding

-D

You have reverse shell and want Kali to proxy via victim to scan/enumerate

SSH from victim to Kali

❌ No

βœ… Yes

Remote Dynamic Port Forwarding

-R (SOCKS)


Local Port Forwarding (-L)

You can SSH into a box and want to access an internal host from there.

ssh -N -L [KALI_PORT]:[TARGET_IP]:[TARGET_PORT] user@<pivot-box>

Example:

ssh -N -L 4455:172.16.217.217:445 user@10.4.217.215

Remote Port Forwarding (-R)

You have reverse shell and want Kali to access something the victim can reach.

ssh -N -R [KALI_PORT]:[TARGET_IP]:[TARGET_PORT] kali@<your-kali-ip>

Example:


Dynamic Port Forwarding (-D)

You can SSH into a pivot box and want to explore or scan targets via proxychains.

Example:

Then in /etc/proxychains4.conf:


Remote Dynamic Port Forwarding (-R + SOCKS)

You have reverse shell and want to proxy traffic from Kali through victim.

Example:

Then in /etc/proxychains4.conf:

Last updated