Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Forward SSH connections based on user name

I found numerous sites explaining ssh port forwarding, ssh reverse proxy, ssh multiplexing etc. involving sshpiper, sslh, running a ssh socks server, just configuring the local SSH server an so on.. so I'm quite puzzled right now and might ask a very common and/or simple question:

As you might already guess from the title I want to set up a git server (GitLab) inside a docker container listening for SSH connections on port 22 without having to use a different port for default ssh operations (terminal, scp, etc..) on the host (as suggested here)

I.e.

  • ssh [email protected] should still be possible as well as
  • git clone [email protected]:path/to/project
  • and I don't want to do any setup on the client computer

If you prefer a picture:

                                      +------ myserver.org --------+
                                      |  +----+     +- typical -+  |
+--------+   [email protected]:22    |  |    |     |   SSH     |  |
| client |  ---------------------->  -+--+----+---->|  service  |  |
+--------+     all names but `git`    |  | ?  |     +-----------+  |
                                      |  |    |                    |
                                      |  | ?  |     +- docker --+  |
+--------+   [email protected]:22      |  |    |     |   with    |  |
| client |  ---------------------->  -+--+----+---->|  GitLab   |  |
+--------+      only user `git`       |  |    |     |           |  |
                                      |  +----+     +-----------+  |
                                      +----------------------------+

Can you tell me what's the recommended/most common way to do this? This question sounds promising but the answer seems to configure the client (which I want to avoid)

like image 252
frans Avatar asked Aug 31 '25 03:08

frans


1 Answers

This project may help you. https://github.com/tg123/sshpiper.

SSH Piper works as a proxy-like ware, and route connections by username, src ip , etc.

+---------+                      +------------------+          +-----------------+
|         |                      |                  |          |                 |
|   Bob   +----ssh -l bob----+   |   SSH Piper   +------------->   Bob' machine  |
|         |                  |   |               |  |          |                 |
+---------+                  |   |               |  |          +-----------------+
                             +---> pipe-by-name--+  |                             
+---------+                  |   |               |  |          +-----------------+
|         |                  |   |               |  |          |                 |
|  Alice  +----ssh -l alice--+   |               +------------->  Alice' machine |
|         |                      |                  |          |                 |
+---------+                      +------------------+          +-----------------+


 Downstream                         SSH Piper                       Upstream                     
like image 136
GooGee Avatar answered Sep 02 '25 19:09

GooGee