# SSH Timeout Proxy

## Description
SSH Timeout Proxy is a simple TCP reverse proxy designed to handle SSH connections, forwarding them to a specified backend SSH server and enforcing a maximum connection duration. It utilizes environment variables to configure the backend SSH server's address and the maximum allowed connection duration, making it flexible for various deployment environments.

## Requirements
- **Go** (at least Go 1.13) - To run the program.
- **SSH Server** - The backend server where SSH connections should be forwarded. Typically, this is `localhost:22` for testing purposes.

## Installation
1. **Clone the repository:**
   ```bash
   git clone https://example.com/ssh-timeout-proxy.git
   cd ssh-timeout-proxy
   ```

2. **Build the project:**
   ```bash
   go build -o ssh-timeout
   ```

## Configuration
The application uses two environment variables:
- `SSH_BACKEND`: Specifies the IP address and port of the backend SSH server (e.g., "localhost:22").
- `SSH_MAX_DURATION`: Specifies the maximum duration (in seconds) that a connection should be allowed to persist.

## Usage
To run the application, use the following command, setting the environment variables as needed:

```bash
SSH_BACKEND="your_backend_ip:port" SSH_MAX_DURATION="duration_in_seconds" ./ssh-timeout
```

For example, to set the backend SSH server to `localhost` on port `22` and limit connection duration to 600 seconds (10 minutes), you would use:

```bash
SSH_BACKEND="localhost:22" SSH_MAX_DURATION="600" ./ssh-timeout
```

## Testing
To test the SSH Timeout Proxy, perform the following steps:

1. **Start the Proxy:**
   Run the proxy with the desired backend and maximum duration configuration as shown in the Usage section.

2. **SSH Through the Proxy:**
   In a separate terminal window, use SSH to connect through the proxy:
   ```bash
   ssh -p 2222 your-username@localhost
   ```
   Replace `your-username` with your actual username, and ensure you connect to the port where the proxy listens (default `2222`).

3. **Observe:**
   Monitor the terminal running the proxy to see the connection and disconnection logs. Ensure the connection is terminated after the specified duration.

## Contributing
Contributions to the SSH Timeout Proxy are welcome. Please feel free to fork the repository, make changes, and submit pull requests.
