---
name: ssh-proxy
description: Establishes local SSH port forwarding (a secure tunnel) from your machine to a remote server. It uses the ssh -N -L command to map a local port to a remote port without opening an interactive shell session. 
when_to_use: When there is a need to "open an ssh proxy", "tunnel the database", or establish a connection to a remote server, When `db-query` or another database interaction fails because the target server is only accessible via an SSH jump host.
---
The `ssh-proxy` skill establishes local SSH port forwarding. Use this when you need to access a remote database or service securely over SSH, such as tunneling a remote PostgreSQL database to your local machine.

## Workflow

To establish the port forward, run the following command in the background or in a separate terminal (note the `-N` flag prevents executing a remote command and just forwards ports):

```bash
ssh -N -L [PORT_FORWARD]:127.0.0.1:[PORT_SERVER] <user>@<host>
```

### Parameters:
- `[PORT_FORWARD]`: The local port on your machine (e.g., `5432` or `5433`).
- `[PORT_SERVER]`: The remote port on the destination server (e.g., `5432` for PostgreSQL).
- `<user>@<host>`: The SSH credentials and host provided.

*Example:* To forward the remote database port 5432 to local port 5433 via `admin@192.168.1.100`:
```bash
ssh -N -L 5433:127.0.0.1:5432 admin@192.168.1.100
```

## Rules
1. Ensure `user@host` is provided.
2. Default the `PORT_SERVER` to `5432` (PostgreSQL) unless specified otherwise.
3. Once the tunnel is open, the service is available locally at `127.0.0.1:[PORT_FORWARD]`.
