Redirect ssh trafic for one user through another portssh-agent forwarding and sudo to another userForced per-user ssh portSelecting Interface for SSH Port ForwardingSSH & SFTP: Should I assign one port to each user to facilitate bandwidth monitoring?Prerouting SSH to different internal portCan I make sshd forward connections to another port for a specific user?SSH to Remote host via another hostHow to remove a port bind still used by sshd after an improper deconnection from ssh?Redirect SSH connexion to another port in function of (sub)domaineForward one SSH user login to a different SSH server

How to modify a string without altering its text properties

Counterfeit checks were created for my account. How does this type of fraud work?

Freewill and rewarding dogs

In a list with unique pairs A, B, how can I sort them so that the last B is the first A in the next pair?

How much steel armor can you wear and still be able to swim?

Why is Havana covered in 5-digit numbers in Our Man in Havana?

Leaving job close to major deadlines

Can the pre-order traversal of two different trees be the same even though they are different?

Kelvin type connection

What kind of chart is this?

What is this airplane that sits in front of Barringer High School in Newark, NJ?

King or Queen-Which piece is which?

Why does a Force divides equally on a Multiple Support/Legs?

Am I legally required to provide a (GPL licensed) source code even after a project is abandoned?

Story of a Witch Boy

Parse JSON in LWC

「捨ててしまう」why is there two て’s used here?

Why are there no file insertion syscalls

Draw a symmetric alien head

What is that ceiling compartment of a Boeing 737?

Are there examples of rowers who also fought?

How do you transpose samples in cents?

How would one carboxylate CBG into its acid form, CBGA?

60's (or earlier) sci-fi short story about two spacecrafts exchanging plants for gold and thinking they got the better of the exchange



Redirect ssh trafic for one user through another port


ssh-agent forwarding and sudo to another userForced per-user ssh portSelecting Interface for SSH Port ForwardingSSH & SFTP: Should I assign one port to each user to facilitate bandwidth monitoring?Prerouting SSH to different internal portCan I make sshd forward connections to another port for a specific user?SSH to Remote host via another hostHow to remove a port bind still used by sshd after an improper deconnection from ssh?Redirect SSH connexion to another port in function of (sub)domaineForward one SSH user login to a different SSH server






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








4















Is it possible to have a configuration like this:



  • A server which listen ssh connections on port 22 as usual

  • For one user (let's say git) redirect all the traffic through another port (2222 for instance)

As a result the command ssh git@host will produce the same result as ssh -p 2222 git@host.



Basically I try to have a sort of reverse proxy on ssh but as I know we can't use sub domains to distinguish ssh incoming connection, I was wondering if we can accomplish this kind of thing with an user approach.



Edit:



The reason is I have set up a gitolite server in a Docker container so at the end I have a ssh daemon which listen on the port 2222 for git purpose.
Additionally I have a "regular" ssh daemon which listen on the port 22 (and I want keep it).



Of course I can access to the git server through the port 2222 (if I open it from the outside) but I was wondering if I can use the "regular" ssh server from remote and then locally redirect it to the "git" ssh for the user git.



So the traffic will be something like this for the user git:



client <==> 22:server:2222:git_container










share|improve this question
























  • What are you trying to accomplish?

    – Michael Hampton
    Sep 8 '14 at 15:29






  • 1





    Could you rephrase and add more info about the "reverse proxy" thing you want? You can force a local user to always connect using a default SSH port instead of regular 22 (local user, not remote user), and set up a server to listen on several ports, but as per sshd_config you cannot have a match for a user with a specific port related directly.

    – NuTTyX
    Sep 8 '14 at 17:27











  • I added some details, I hope it's more understandable. I think that I want is not possible but it's the best place to get fixed.

    – FabiF
    Sep 8 '14 at 22:56







  • 1





    I'm dealing with similar requirements and it looks like sshpiper is what we need: github.com/tg123/sshpiper

    – dumolibr
    May 6 '15 at 15:34











  • @dumolibr Thanks a lot, it's exactly what I was looking for.

    – FabiF
    May 7 '15 at 8:36

















4















Is it possible to have a configuration like this:



  • A server which listen ssh connections on port 22 as usual

  • For one user (let's say git) redirect all the traffic through another port (2222 for instance)

As a result the command ssh git@host will produce the same result as ssh -p 2222 git@host.



Basically I try to have a sort of reverse proxy on ssh but as I know we can't use sub domains to distinguish ssh incoming connection, I was wondering if we can accomplish this kind of thing with an user approach.



Edit:



The reason is I have set up a gitolite server in a Docker container so at the end I have a ssh daemon which listen on the port 2222 for git purpose.
Additionally I have a "regular" ssh daemon which listen on the port 22 (and I want keep it).



Of course I can access to the git server through the port 2222 (if I open it from the outside) but I was wondering if I can use the "regular" ssh server from remote and then locally redirect it to the "git" ssh for the user git.



So the traffic will be something like this for the user git:



client <==> 22:server:2222:git_container










share|improve this question
























  • What are you trying to accomplish?

    – Michael Hampton
    Sep 8 '14 at 15:29






  • 1





    Could you rephrase and add more info about the "reverse proxy" thing you want? You can force a local user to always connect using a default SSH port instead of regular 22 (local user, not remote user), and set up a server to listen on several ports, but as per sshd_config you cannot have a match for a user with a specific port related directly.

    – NuTTyX
    Sep 8 '14 at 17:27











  • I added some details, I hope it's more understandable. I think that I want is not possible but it's the best place to get fixed.

    – FabiF
    Sep 8 '14 at 22:56







  • 1





    I'm dealing with similar requirements and it looks like sshpiper is what we need: github.com/tg123/sshpiper

    – dumolibr
    May 6 '15 at 15:34











  • @dumolibr Thanks a lot, it's exactly what I was looking for.

    – FabiF
    May 7 '15 at 8:36













4












4








4


1






Is it possible to have a configuration like this:



  • A server which listen ssh connections on port 22 as usual

  • For one user (let's say git) redirect all the traffic through another port (2222 for instance)

As a result the command ssh git@host will produce the same result as ssh -p 2222 git@host.



Basically I try to have a sort of reverse proxy on ssh but as I know we can't use sub domains to distinguish ssh incoming connection, I was wondering if we can accomplish this kind of thing with an user approach.



Edit:



The reason is I have set up a gitolite server in a Docker container so at the end I have a ssh daemon which listen on the port 2222 for git purpose.
Additionally I have a "regular" ssh daemon which listen on the port 22 (and I want keep it).



Of course I can access to the git server through the port 2222 (if I open it from the outside) but I was wondering if I can use the "regular" ssh server from remote and then locally redirect it to the "git" ssh for the user git.



So the traffic will be something like this for the user git:



client <==> 22:server:2222:git_container










share|improve this question
















Is it possible to have a configuration like this:



  • A server which listen ssh connections on port 22 as usual

  • For one user (let's say git) redirect all the traffic through another port (2222 for instance)

As a result the command ssh git@host will produce the same result as ssh -p 2222 git@host.



Basically I try to have a sort of reverse proxy on ssh but as I know we can't use sub domains to distinguish ssh incoming connection, I was wondering if we can accomplish this kind of thing with an user approach.



Edit:



The reason is I have set up a gitolite server in a Docker container so at the end I have a ssh daemon which listen on the port 2222 for git purpose.
Additionally I have a "regular" ssh daemon which listen on the port 22 (and I want keep it).



Of course I can access to the git server through the port 2222 (if I open it from the outside) but I was wondering if I can use the "regular" ssh server from remote and then locally redirect it to the "git" ssh for the user git.



So the traffic will be something like this for the user git:



client <==> 22:server:2222:git_container







ssh port port-forwarding






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Sep 8 '14 at 22:52







FabiF

















asked Sep 8 '14 at 15:18









FabiFFabiF

1213




1213












  • What are you trying to accomplish?

    – Michael Hampton
    Sep 8 '14 at 15:29






  • 1





    Could you rephrase and add more info about the "reverse proxy" thing you want? You can force a local user to always connect using a default SSH port instead of regular 22 (local user, not remote user), and set up a server to listen on several ports, but as per sshd_config you cannot have a match for a user with a specific port related directly.

    – NuTTyX
    Sep 8 '14 at 17:27











  • I added some details, I hope it's more understandable. I think that I want is not possible but it's the best place to get fixed.

    – FabiF
    Sep 8 '14 at 22:56







  • 1





    I'm dealing with similar requirements and it looks like sshpiper is what we need: github.com/tg123/sshpiper

    – dumolibr
    May 6 '15 at 15:34











  • @dumolibr Thanks a lot, it's exactly what I was looking for.

    – FabiF
    May 7 '15 at 8:36

















  • What are you trying to accomplish?

    – Michael Hampton
    Sep 8 '14 at 15:29






  • 1





    Could you rephrase and add more info about the "reverse proxy" thing you want? You can force a local user to always connect using a default SSH port instead of regular 22 (local user, not remote user), and set up a server to listen on several ports, but as per sshd_config you cannot have a match for a user with a specific port related directly.

    – NuTTyX
    Sep 8 '14 at 17:27











  • I added some details, I hope it's more understandable. I think that I want is not possible but it's the best place to get fixed.

    – FabiF
    Sep 8 '14 at 22:56







  • 1





    I'm dealing with similar requirements and it looks like sshpiper is what we need: github.com/tg123/sshpiper

    – dumolibr
    May 6 '15 at 15:34











  • @dumolibr Thanks a lot, it's exactly what I was looking for.

    – FabiF
    May 7 '15 at 8:36
















What are you trying to accomplish?

– Michael Hampton
Sep 8 '14 at 15:29





What are you trying to accomplish?

– Michael Hampton
Sep 8 '14 at 15:29




1




1





Could you rephrase and add more info about the "reverse proxy" thing you want? You can force a local user to always connect using a default SSH port instead of regular 22 (local user, not remote user), and set up a server to listen on several ports, but as per sshd_config you cannot have a match for a user with a specific port related directly.

– NuTTyX
Sep 8 '14 at 17:27





Could you rephrase and add more info about the "reverse proxy" thing you want? You can force a local user to always connect using a default SSH port instead of regular 22 (local user, not remote user), and set up a server to listen on several ports, but as per sshd_config you cannot have a match for a user with a specific port related directly.

– NuTTyX
Sep 8 '14 at 17:27













I added some details, I hope it's more understandable. I think that I want is not possible but it's the best place to get fixed.

– FabiF
Sep 8 '14 at 22:56






I added some details, I hope it's more understandable. I think that I want is not possible but it's the best place to get fixed.

– FabiF
Sep 8 '14 at 22:56





1




1





I'm dealing with similar requirements and it looks like sshpiper is what we need: github.com/tg123/sshpiper

– dumolibr
May 6 '15 at 15:34





I'm dealing with similar requirements and it looks like sshpiper is what we need: github.com/tg123/sshpiper

– dumolibr
May 6 '15 at 15:34













@dumolibr Thanks a lot, it's exactly what I was looking for.

– FabiF
May 7 '15 at 8:36





@dumolibr Thanks a lot, it's exactly what I was looking for.

– FabiF
May 7 '15 at 8:36










2 Answers
2






active

oldest

votes


















0














A simple TCP port-forwarding can't do it: the username is only mentioned further into the SSH protocol, so if you insist on starting off with ssh git@host, then there have to be two full SSH authentication handshakes. I am not aware of a generic SSH-proxy that could do that transparently. You could automate the second hop server-side, e.g. by making a shell script ssh -p 2222 localhost the user's shell on the outer host. But that would be not compatible with lots of SSH's nice perks, like port-forwarding, sftp, scp, ...



A better way would be to customize the client side. E.g. in ~/.ssh/config



Host git_host
Hostname host
Port 2222
Username git


and then ssh git_host (instead of ssh git@host).



If you have to walk through the outer host first (e.g. because you have no direct visibility to port 2222), then you could use these tricks here, e.g.



Host git_host
Hostname host
Username git
ProxyCommand ssh -q git@host nc -q0 localhost 2222


(might not be 100% correct, play with the options)






share|improve this answer

























  • I'm trying to avoid client side customization (sadly a minor ssh configuration can be too much for some users...). But it sounds like I have no user transparently solution, I'm not so surprised. Thanks for your time.

    – FabiF
    Sep 9 '14 at 10:09







  • 1





    Maybe you can have a 2nd IP address on the host and portforward its port 22?

    – Nils Toedtmann
    Sep 9 '14 at 10:36



















0














Configure your regular SSH server to listen on a non standard port. Then you can configure gitolite to use the now free port 22.



This makes it easy for your users, and you seem capable enough to use ssh on a different port.






share|improve this answer























    Your Answer








    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "2"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader:
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    ,
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );













    draft saved

    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fserverfault.com%2fquestions%2f627030%2fredirect-ssh-trafic-for-one-user-through-another-port%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown

























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    A simple TCP port-forwarding can't do it: the username is only mentioned further into the SSH protocol, so if you insist on starting off with ssh git@host, then there have to be two full SSH authentication handshakes. I am not aware of a generic SSH-proxy that could do that transparently. You could automate the second hop server-side, e.g. by making a shell script ssh -p 2222 localhost the user's shell on the outer host. But that would be not compatible with lots of SSH's nice perks, like port-forwarding, sftp, scp, ...



    A better way would be to customize the client side. E.g. in ~/.ssh/config



    Host git_host
    Hostname host
    Port 2222
    Username git


    and then ssh git_host (instead of ssh git@host).



    If you have to walk through the outer host first (e.g. because you have no direct visibility to port 2222), then you could use these tricks here, e.g.



    Host git_host
    Hostname host
    Username git
    ProxyCommand ssh -q git@host nc -q0 localhost 2222


    (might not be 100% correct, play with the options)






    share|improve this answer

























    • I'm trying to avoid client side customization (sadly a minor ssh configuration can be too much for some users...). But it sounds like I have no user transparently solution, I'm not so surprised. Thanks for your time.

      – FabiF
      Sep 9 '14 at 10:09







    • 1





      Maybe you can have a 2nd IP address on the host and portforward its port 22?

      – Nils Toedtmann
      Sep 9 '14 at 10:36
















    0














    A simple TCP port-forwarding can't do it: the username is only mentioned further into the SSH protocol, so if you insist on starting off with ssh git@host, then there have to be two full SSH authentication handshakes. I am not aware of a generic SSH-proxy that could do that transparently. You could automate the second hop server-side, e.g. by making a shell script ssh -p 2222 localhost the user's shell on the outer host. But that would be not compatible with lots of SSH's nice perks, like port-forwarding, sftp, scp, ...



    A better way would be to customize the client side. E.g. in ~/.ssh/config



    Host git_host
    Hostname host
    Port 2222
    Username git


    and then ssh git_host (instead of ssh git@host).



    If you have to walk through the outer host first (e.g. because you have no direct visibility to port 2222), then you could use these tricks here, e.g.



    Host git_host
    Hostname host
    Username git
    ProxyCommand ssh -q git@host nc -q0 localhost 2222


    (might not be 100% correct, play with the options)






    share|improve this answer

























    • I'm trying to avoid client side customization (sadly a minor ssh configuration can be too much for some users...). But it sounds like I have no user transparently solution, I'm not so surprised. Thanks for your time.

      – FabiF
      Sep 9 '14 at 10:09







    • 1





      Maybe you can have a 2nd IP address on the host and portforward its port 22?

      – Nils Toedtmann
      Sep 9 '14 at 10:36














    0












    0








    0







    A simple TCP port-forwarding can't do it: the username is only mentioned further into the SSH protocol, so if you insist on starting off with ssh git@host, then there have to be two full SSH authentication handshakes. I am not aware of a generic SSH-proxy that could do that transparently. You could automate the second hop server-side, e.g. by making a shell script ssh -p 2222 localhost the user's shell on the outer host. But that would be not compatible with lots of SSH's nice perks, like port-forwarding, sftp, scp, ...



    A better way would be to customize the client side. E.g. in ~/.ssh/config



    Host git_host
    Hostname host
    Port 2222
    Username git


    and then ssh git_host (instead of ssh git@host).



    If you have to walk through the outer host first (e.g. because you have no direct visibility to port 2222), then you could use these tricks here, e.g.



    Host git_host
    Hostname host
    Username git
    ProxyCommand ssh -q git@host nc -q0 localhost 2222


    (might not be 100% correct, play with the options)






    share|improve this answer















    A simple TCP port-forwarding can't do it: the username is only mentioned further into the SSH protocol, so if you insist on starting off with ssh git@host, then there have to be two full SSH authentication handshakes. I am not aware of a generic SSH-proxy that could do that transparently. You could automate the second hop server-side, e.g. by making a shell script ssh -p 2222 localhost the user's shell on the outer host. But that would be not compatible with lots of SSH's nice perks, like port-forwarding, sftp, scp, ...



    A better way would be to customize the client side. E.g. in ~/.ssh/config



    Host git_host
    Hostname host
    Port 2222
    Username git


    and then ssh git_host (instead of ssh git@host).



    If you have to walk through the outer host first (e.g. because you have no direct visibility to port 2222), then you could use these tricks here, e.g.



    Host git_host
    Hostname host
    Username git
    ProxyCommand ssh -q git@host nc -q0 localhost 2222


    (might not be 100% correct, play with the options)







    share|improve this answer














    share|improve this answer



    share|improve this answer








    edited Sep 9 '14 at 10:00

























    answered Sep 9 '14 at 9:40









    Nils ToedtmannNils Toedtmann

    1,68421833




    1,68421833












    • I'm trying to avoid client side customization (sadly a minor ssh configuration can be too much for some users...). But it sounds like I have no user transparently solution, I'm not so surprised. Thanks for your time.

      – FabiF
      Sep 9 '14 at 10:09







    • 1





      Maybe you can have a 2nd IP address on the host and portforward its port 22?

      – Nils Toedtmann
      Sep 9 '14 at 10:36


















    • I'm trying to avoid client side customization (sadly a minor ssh configuration can be too much for some users...). But it sounds like I have no user transparently solution, I'm not so surprised. Thanks for your time.

      – FabiF
      Sep 9 '14 at 10:09







    • 1





      Maybe you can have a 2nd IP address on the host and portforward its port 22?

      – Nils Toedtmann
      Sep 9 '14 at 10:36

















    I'm trying to avoid client side customization (sadly a minor ssh configuration can be too much for some users...). But it sounds like I have no user transparently solution, I'm not so surprised. Thanks for your time.

    – FabiF
    Sep 9 '14 at 10:09






    I'm trying to avoid client side customization (sadly a minor ssh configuration can be too much for some users...). But it sounds like I have no user transparently solution, I'm not so surprised. Thanks for your time.

    – FabiF
    Sep 9 '14 at 10:09





    1




    1





    Maybe you can have a 2nd IP address on the host and portforward its port 22?

    – Nils Toedtmann
    Sep 9 '14 at 10:36






    Maybe you can have a 2nd IP address on the host and portforward its port 22?

    – Nils Toedtmann
    Sep 9 '14 at 10:36














    0














    Configure your regular SSH server to listen on a non standard port. Then you can configure gitolite to use the now free port 22.



    This makes it easy for your users, and you seem capable enough to use ssh on a different port.






    share|improve this answer



























      0














      Configure your regular SSH server to listen on a non standard port. Then you can configure gitolite to use the now free port 22.



      This makes it easy for your users, and you seem capable enough to use ssh on a different port.






      share|improve this answer

























        0












        0








        0







        Configure your regular SSH server to listen on a non standard port. Then you can configure gitolite to use the now free port 22.



        This makes it easy for your users, and you seem capable enough to use ssh on a different port.






        share|improve this answer













        Configure your regular SSH server to listen on a non standard port. Then you can configure gitolite to use the now free port 22.



        This makes it easy for your users, and you seem capable enough to use ssh on a different port.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Jun 2 at 6:57









        Gerald SchneiderGerald Schneider

        7,31832748




        7,31832748



























            draft saved

            draft discarded
















































            Thanks for contributing an answer to Server Fault!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid


            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.

            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fserverfault.com%2fquestions%2f627030%2fredirect-ssh-trafic-for-one-user-through-another-port%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Wikipedia:Vital articles Мазмуну Biography - Өмүр баян Philosophy and psychology - Философия жана психология Religion - Дин Social sciences - Коомдук илимдер Language and literature - Тил жана адабият Science - Илим Technology - Технология Arts and recreation - Искусство жана эс алуу History and geography - Тарых жана география Навигация менюсу

            Bruxelas-Capital Índice Historia | Composición | Situación lingüística | Clima | Cidades irmandadas | Notas | Véxase tamén | Menú de navegacióneO uso das linguas en Bruxelas e a situación do neerlandés"Rexión de Bruxelas Capital"o orixinalSitio da rexiónPáxina de Bruselas no sitio da Oficina de Promoción Turística de Valonia e BruxelasMapa Interactivo da Rexión de Bruxelas-CapitaleeWorldCat332144929079854441105155190212ID28008674080552-90000 0001 0666 3698n94104302ID540940339365017018237

            What should I write in an apology letter, since I have decided not to join a company after accepting an offer letterShould I keep looking after accepting a job offer?What should I do when I've been verbally told I would get an offer letter, but still haven't gotten one after 4 weeks?Do I accept an offer from a company that I am not likely to join?New job hasn't confirmed starting date and I want to give current employer as much notice as possibleHow should I address my manager in my resignation letter?HR delayed background verification, now jobless as resignedNo email communication after accepting a formal written offer. How should I phrase the call?What should I do if after receiving a verbal offer letter I am informed that my written job offer is put on hold due to some internal issues?Should I inform the current employer that I am about to resign within 1-2 weeks since I have signed the offer letter and waiting for visa?What company will do, if I send their offer letter to another company