Merge pull request #682 from LGD-P/ssh_tunneling

SSH Tunneling
This commit is contained in:
Fechin authored and GitHub committed 2025-06-18 20:02:47 +08:00
commit b1b2eadbf3
1 file changed
+60
+60
View File
@@ -249,7 +249,67 @@ $ ssh-keygen -R <ip/hostname>
- PEM
- PKCS8
## SSH Tunneling
### SSH Tunnel Options {.row-span-2}
| Option | Description |
|--------|:--------------------------------------------------------|
| `-L` | Local port forwarding |
| `-R` | Remote port forwarding |
| `-D` | Dynamic port forwarding |
| `-f` | Run in background |
| `-N` | Do not execute a remote command |
| `-g` | Allow remote hosts to connect to local forwarded ports |
{.left-text}
more details on flag above with `man ssh`
### Local Port Forwarding {.col-span-2}
```bash
# Forward a local port to a remote server
ssh -L local_port:remote_host:remote_port user@ssh_server
# Example: Forward local port 8080 to remote port 80 on example.com
ssh -L 8080:example.com:80 user@ssh_server
```
### Dynamic Port Forwarding {.col-span-2}
```bash
# Create a SOCKS proxy on a local port
ssh -D local_port user@ssh_server
# Create a SOCKS proxy on local port 1080 in the background
ssh -f -N -D 1080 user@ssh_server
```
### Background Tunnel {.col-span-3}
```bash
# Create a local port forwarding tunnel in the background
ssh -f -N -L local_port:remote_host:remote_port user@ssh_server
```
### Multiple Tunnels {.col-span-3}
```bash
# Create multiple tunnels in a single SSH command
ssh -L 8080:example.com:80 -L 3306:db.example.com:3306 user@ssh_server
```
### Combining Options {.col-span-3}
```bash
# In background, no command, allow remote host, local port forward, identity_file
ssh -f -N -g -L 8080:example.com:80 -i ~/.ssh/custom_key user@ssh_server
```
## Also see
- [OpenSSH Config File Examples](https://www.cyberciti.biz/faq/create-ssh-config-file-on-linux-unix/) _(cyberciti.biz)_
- [ssh_config](https://linux.die.net/man/5/ssh_config) _(linux.die.net)_
- [man-ssh](https://man7.org/linux/man-pages/man1/ssh.1.html)