Establish a SSH tunnel to access a remote server behind firewall

  • To start the tunnel (running background):
    ssh -L ${LOCAL_HOST}:${LOCAL_PORT}:${REMOTE_HOST}:${REMOTE_PORT} ${GATEWAY_USER}@${GATEWAY_HOST} -N -f -M -S ${SSH_CTRL_PATH}
    for example:
    ssh -L localhost:3389:192.168.20.10:3389 john@gateway-ssh-server.johns.org -N -f -M -S /tmp/ssh-tunnel.3389
    The command above starts the ssh tunnel (and keeps the ssh process running background.) After the tunnel is established, you can access the remote server port(192.168.20.10) via local port(localhost:3389).
  • To stop the tunnel (running background):
    ssh -S ${SSH_CTRL_PATH} -O exit ${GATEWAY_USER}@${GATEWAY_HOST}
    for example:
    ssh -S /tmp/ssh-tunnel.3389 -O exit john@gateway-ssh-server.johns.org

No comments:

Post a Comment