Ssh – How to set up a server for reverse SSH tunneling that can be used by multiple users

amazon-web-servicessshssh-tunnel

Sorry for the wall of text, I'm a bit of a newbie but have exhausted my search resources.

In order to establish a public IP for my local Django development server, I set up an AWS micro instance as a server for reverse SSH tunneling. The public IP points to the tunnel server, and I create a reverse tunnel from my local machine to the tunnel server which forwards traffic between the public IP and my machine. Here's the command if you're interested:

autossh -M 8001:8001 -NR 80:localhost:8000 root@mytunnelserver.com -v

I am now working on on-boarding another developer and need to set up something similar for him. I could create a clone of my setup (essentially creating a new tunnel server just for him) but that seems messy, especially as I need to add more developers in the future.

Is there a way to set up a single server that multiple users can use for setting up reverse SSH tunnels, considering those users have unique public IPs but are forwarding the same ports? Basically, can both me and my partner use the same server for reverse SSH tunneling, properly forwarding traffic across the same ports for different public IPs?

Thanks in advance and please let me know if I can clarify.

Best Answer

we use it that way:

install a local script for the tunnel (so you don't have to remember :) ) - like:

_username_local.domain.org.sh_

#!/bin/sh
echo "local: 8080 - remote: 8081"
echo "http://username-local.domain.org/"
ssh root@domain.org -R 8081:localhost:8080 -g

so the first user listens on the remote port 8081, the second on 8082 etc.

on the server setup nginx as reverse proxy, one 'server' per user:

upstream user_1 {
    server localhost:8081 fail_timeout=0;
}
server {
    listen   80;
    server_name username-local.domain.org;
    location / {
        proxy_redirect off;
        proxy_pass   http://user_1;
    }
}

and don't forget to set create the dns entries... (probably with wildcard to *.domain.org)