Skip to content

Instantly share code, notes, and snippets.

@socheatsok78
Last active April 27, 2023 08:46
Show Gist options
  • Save socheatsok78/9666b7d59078bc407f44514fbde8b72a to your computer and use it in GitHub Desktop.
Save socheatsok78/9666b7d59078bc407f44514fbde8b72a to your computer and use it in GitHub Desktop.
Poor man's reverse proxy with SSH

Usage

Install the service by adding the ssh-reverse-proxy@.service to /lib/systemd/system/.

Create a config for a service:

Example:

# /etc/default/ssh-reverse-proxy@your-service

LOCAL_ADDR=localhost
LOCAL_PORT=3535
REMOTE_ADDR=10.10.20.1 # The remote addr to proxy
REMOTE_PORT=3535 # The remote port to proxy
[Unit]
Description=SSH proxy daemon %I
Requires=network.target
[Service]
; User=your-user
; Group=your-group
Environment="LOCAL_ADDR=localhost"
Environment="LOCAL_PORT=3535"
Environment="REMOTE_ADDR=localhost"
Environment="REMOTE_PORT=3535"
EnvironmentFile=/etc/default/ssh-reverse-proxy@%i
ExecStart=ssh -NT -o StrictHostKeyChecking=no -o ServerAliveInterval=60 -o ExitOnForwardFailure=yes -R ${LOCAL_ADDR}:${LOCAL_PORT}:${REMOTE_ADDR}:${REMOTE_PORT} ${REMOTE}
# Restart every >2 seconds to avoid StartLimitInterval failure
RestartSec=5
Restart=always
[Install]
WantedBy=multi-user.target
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment