# SSH Port Forwarding

### Overview

SSH port forwarding is a mechanism in SSH for tunneling application ports from the client machine to the server machine, or vice versa. It can be used for adding encryption to legacy applications, going through firewalls, and some system administrators and IT professionals use it for opening backdoors into the internal network from their home machines. It can also be abused by hackers and malware to open access from the Internet to the internal network.

### Local Port Forwarding

2 example commands for local port forwarding are shown below:

```bash
ssh -f -N gokul@gokul-ubuntu -L 5555:172.17.0.1:4444
# -f -> Option to request ssh to go to the background
# -N -> Do not execute the remote command
# 5555 -> The port on the local machine which the ssh client will listen on.
# gokul-ubuntu -> This is the SSH server which is going to tunnel our connection.
# 172.17.0.1:4444 -> This is the resource which we want to access from the SSH server(gokul-ubuntu). The sshd server will forward the traffic to this address.

ssh -f -N gokul@192.168.34.45 -L 5555:172.243.32.12:4444
# 5555 -> The port on the local machine which the ssh client will listen on.
# 192.168.34.45 -> This is the SSH server which is going to tunnel our connection.
# 172.243.32.12:4444 -> This is the resource which we want to access from the SSH server(gokul-ubuntu). The sshd server will forward the traffic to this address.
# In this case, this address is the address of the 2nd machine which can only be accessed from the first machine (192.168.34.45)
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://gokulkarthik.gitbook.io/pentesting-checklist/pivoting/ssh-port-forwarding.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
