2.3 KiB
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
-
Clone the repository:
git clone https://example.com/ssh-timeout-proxy.git cd ssh-timeout-proxy
-
Build the project:
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:
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:
SSH_BACKEND="localhost:22" SSH_MAX_DURATION="600" ./ssh-timeout
Testing
To test the SSH Timeout Proxy, perform the following steps:
-
Start the Proxy: Run the proxy with the desired backend and maximum duration configuration as shown in the Usage section.
-
SSH Through the Proxy: In a separate terminal window, use SSH to connect through the proxy:
ssh -p 2222 your-username@localhost
Replace
your-username
with your actual username, and ensure you connect to the port where the proxy listens (default2222
). -
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.