Reverse SSH tunnel with AutoSSH












0














How to apply dynamic port allocation in AutoSSH?
In the remote device using ssh we make a reverse tunnel by this command:
ssh -f -N -R 0:localhost:22 username@ip



It allocates a dynamic port on the server and prints that port on the machine . I want to apply the same thing using autossh.



So my question how can I achieve this?










share|improve this question





























    0














    How to apply dynamic port allocation in AutoSSH?
    In the remote device using ssh we make a reverse tunnel by this command:
    ssh -f -N -R 0:localhost:22 username@ip



    It allocates a dynamic port on the server and prints that port on the machine . I want to apply the same thing using autossh.



    So my question how can I achieve this?










    share|improve this question



























      0












      0








      0







      How to apply dynamic port allocation in AutoSSH?
      In the remote device using ssh we make a reverse tunnel by this command:
      ssh -f -N -R 0:localhost:22 username@ip



      It allocates a dynamic port on the server and prints that port on the machine . I want to apply the same thing using autossh.



      So my question how can I achieve this?










      share|improve this question















      How to apply dynamic port allocation in AutoSSH?
      In the remote device using ssh we make a reverse tunnel by this command:
      ssh -f -N -R 0:localhost:22 username@ip



      It allocates a dynamic port on the server and prints that port on the machine . I want to apply the same thing using autossh.



      So my question how can I achieve this?







      ssh-tunneling autossh






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Dec 19 '17 at 17:30









      muhammad

      546515




      546515










      asked Dec 19 '17 at 17:20









      Shubham Pandey

      1




      1






















          1 Answer
          1






          active

          oldest

          votes


















          1














          autossh is a near drop-in replacement for ssh ssh. By drop-in replacement I mean you call it instead of ssh and, normally, pass the exact same arguments as you would supply to ssh. The near qualifier to that indicates that you need to provide one additional, non-ssh flag (option plus option argument) to autossh.



          The extra option+arg is -M port. port is the number of an unused port on your system where the adjacent port one higher than itself is also unused. For example, the manpage uses 20000 and 20001 as an example and since those are both free on my system I use those as well. So I pass -M 20000 to autossh.



          If you used the same ports your command would look like...



          autossh -M 20000 -f -N -R 0:localhost:22 username@ip


          FYI these ports are used to monitor availability of the remote. Test data is sent out on 20000 and returned on 20001. If nothing is returned then autossh tries to reestablish a connection (that's simplifying things a bit but you get the point).






          share|improve this answer























            Your Answer








            StackExchange.ready(function() {
            var channelOptions = {
            tags: "".split(" "),
            id: "106"
            };
            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: false,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: null,
            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%2funix.stackexchange.com%2fquestions%2f411866%2freverse-ssh-tunnel-with-autossh%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown

























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            1














            autossh is a near drop-in replacement for ssh ssh. By drop-in replacement I mean you call it instead of ssh and, normally, pass the exact same arguments as you would supply to ssh. The near qualifier to that indicates that you need to provide one additional, non-ssh flag (option plus option argument) to autossh.



            The extra option+arg is -M port. port is the number of an unused port on your system where the adjacent port one higher than itself is also unused. For example, the manpage uses 20000 and 20001 as an example and since those are both free on my system I use those as well. So I pass -M 20000 to autossh.



            If you used the same ports your command would look like...



            autossh -M 20000 -f -N -R 0:localhost:22 username@ip


            FYI these ports are used to monitor availability of the remote. Test data is sent out on 20000 and returned on 20001. If nothing is returned then autossh tries to reestablish a connection (that's simplifying things a bit but you get the point).






            share|improve this answer




























              1














              autossh is a near drop-in replacement for ssh ssh. By drop-in replacement I mean you call it instead of ssh and, normally, pass the exact same arguments as you would supply to ssh. The near qualifier to that indicates that you need to provide one additional, non-ssh flag (option plus option argument) to autossh.



              The extra option+arg is -M port. port is the number of an unused port on your system where the adjacent port one higher than itself is also unused. For example, the manpage uses 20000 and 20001 as an example and since those are both free on my system I use those as well. So I pass -M 20000 to autossh.



              If you used the same ports your command would look like...



              autossh -M 20000 -f -N -R 0:localhost:22 username@ip


              FYI these ports are used to monitor availability of the remote. Test data is sent out on 20000 and returned on 20001. If nothing is returned then autossh tries to reestablish a connection (that's simplifying things a bit but you get the point).






              share|improve this answer


























                1












                1








                1






                autossh is a near drop-in replacement for ssh ssh. By drop-in replacement I mean you call it instead of ssh and, normally, pass the exact same arguments as you would supply to ssh. The near qualifier to that indicates that you need to provide one additional, non-ssh flag (option plus option argument) to autossh.



                The extra option+arg is -M port. port is the number of an unused port on your system where the adjacent port one higher than itself is also unused. For example, the manpage uses 20000 and 20001 as an example and since those are both free on my system I use those as well. So I pass -M 20000 to autossh.



                If you used the same ports your command would look like...



                autossh -M 20000 -f -N -R 0:localhost:22 username@ip


                FYI these ports are used to monitor availability of the remote. Test data is sent out on 20000 and returned on 20001. If nothing is returned then autossh tries to reestablish a connection (that's simplifying things a bit but you get the point).






                share|improve this answer














                autossh is a near drop-in replacement for ssh ssh. By drop-in replacement I mean you call it instead of ssh and, normally, pass the exact same arguments as you would supply to ssh. The near qualifier to that indicates that you need to provide one additional, non-ssh flag (option plus option argument) to autossh.



                The extra option+arg is -M port. port is the number of an unused port on your system where the adjacent port one higher than itself is also unused. For example, the manpage uses 20000 and 20001 as an example and since those are both free on my system I use those as well. So I pass -M 20000 to autossh.



                If you used the same ports your command would look like...



                autossh -M 20000 -f -N -R 0:localhost:22 username@ip


                FYI these ports are used to monitor availability of the remote. Test data is sent out on 20000 and returned on 20001. If nothing is returned then autossh tries to reestablish a connection (that's simplifying things a bit but you get the point).







                share|improve this answer














                share|improve this answer



                share|improve this answer








                edited Dec 17 at 21:17

























                answered Dec 19 '17 at 21:28









                B Layer

                4,0141525




                4,0141525






























                    draft saved

                    draft discarded




















































                    Thanks for contributing an answer to Unix & Linux Stack Exchange!


                    • 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.





                    Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


                    Please pay close attention to the following guidance:


                    • 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%2funix.stackexchange.com%2fquestions%2f411866%2freverse-ssh-tunnel-with-autossh%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

                    Morgemoulin

                    Scott Moir

                    Souastre