SSH RemoteForward fails with shared Control Socket The 2019 Stack Overflow Developer Survey Results Are InCan I make ssh tell me which control file it would use for multiplexing?Is there any way to use session multiplexing (Control Master) from windows?Adding port forwardings programmatically on a ControlMaster SSH sessionSSH port forwarding with a master channelAutomatically spawn a ControlMaster background process on first access to a ssh remote systemOpenSSH disable ControlMaster for given hostnameChange ssh ControlPath with host-specific declarationmacOS port forwarding for remote ssh loginError when SSH forwarding TCP to unix socketrequire existing control master for OpenSSH

Did Scotland spend $250,000 for the slogan "Welcome to Scotland"?

Why isn't the circumferential light around the M87 black hole's event horizon symmetric?

Can withdrawing asylum be illegal?

Why can't devices on different VLANs, but on the same subnet, communicate?

Is it correct to say the Neural Networks are an alternative way of performing Maximum Likelihood Estimation? if not, why?

How to notate time signature switching consistently every measure

What is the most efficient way to store a numeric range?

Can we generate random numbers using irrational numbers like π and e?

How can I add encounters in the Lost Mine of Phandelver campaign without giving PCs too much XP?

How to charge AirPods to keep battery healthy?

Slides for 30 min~1 hr Skype tenure track application interview

What is this business jet?

Is an up-to-date browser secure on an out-of-date OS?

I am an eight letter word. What am I?

Is it ok to offer lower paid work as a trial period before negotiating for a full-time job?

Why doesn't shell automatically fix "useless use of cat"?

Does adding complexity mean a more secure cipher?

Why are there uneven bright areas in this photo of black hole?

What to do when moving next to a bird sanctuary with a loosely-domesticated cat?

Is it safe to harvest rainwater that fell on solar panels?

Is Cinnamon a desktop environment or a window manager? (Or both?)

How can I define good in a religion that claims no moral authority?

How to type a long/em dash `—`

Why does the nucleus not repel itself?



SSH RemoteForward fails with shared Control Socket



The 2019 Stack Overflow Developer Survey Results Are InCan I make ssh tell me which control file it would use for multiplexing?Is there any way to use session multiplexing (Control Master) from windows?Adding port forwardings programmatically on a ControlMaster SSH sessionSSH port forwarding with a master channelAutomatically spawn a ControlMaster background process on first access to a ssh remote systemOpenSSH disable ControlMaster for given hostnameChange ssh ControlPath with host-specific declarationmacOS port forwarding for remote ssh loginError when SSH forwarding TCP to unix socketrequire existing control master for OpenSSH



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








1















My ~/.ssh/config contains:



ControlMaster auto
ControlPath ~/.ssh/socket-%r@%h:%p

Host hostname.example
# TextMate rmate port
RemoteForward :52698 localhost:52698


When I make an initial connection to the host, it successfully creates the master socket file at ~/.ssh-lachlanhunt@hostname.example:22.



But when I open a new terminal and attempt to make a second connection, I get this error:



$ ssh hostname.example
mux_client_forward: forwarding request failed: remote port forwarding failed for listen port 52698
muxclient: master forward request failed
ControlSocket /Users/lachlanhunt/.ssh/socket-lachlanhunt@hostname.example:22 already exists, disabling multiplexing
Warning: remote port forwarding failed for listen port 52698


But if I comment out the RemoteForward line in the config, it's able to successfully reuse the connection, making it connect faster. Is there any way I can configure ssh to support both multiplexed connections and enable the remote port forwarding, such that it only attempts to forward the port if it's the master connection?



My system:



  • macOS Sierra 10.12.6

  • OpenSSH_7.4p1, LibreSSL 2.5.0









share|improve this question




























    1















    My ~/.ssh/config contains:



    ControlMaster auto
    ControlPath ~/.ssh/socket-%r@%h:%p

    Host hostname.example
    # TextMate rmate port
    RemoteForward :52698 localhost:52698


    When I make an initial connection to the host, it successfully creates the master socket file at ~/.ssh-lachlanhunt@hostname.example:22.



    But when I open a new terminal and attempt to make a second connection, I get this error:



    $ ssh hostname.example
    mux_client_forward: forwarding request failed: remote port forwarding failed for listen port 52698
    muxclient: master forward request failed
    ControlSocket /Users/lachlanhunt/.ssh/socket-lachlanhunt@hostname.example:22 already exists, disabling multiplexing
    Warning: remote port forwarding failed for listen port 52698


    But if I comment out the RemoteForward line in the config, it's able to successfully reuse the connection, making it connect faster. Is there any way I can configure ssh to support both multiplexed connections and enable the remote port forwarding, such that it only attempts to forward the port if it's the master connection?



    My system:



    • macOS Sierra 10.12.6

    • OpenSSH_7.4p1, LibreSSL 2.5.0









    share|improve this question
























      1












      1








      1








      My ~/.ssh/config contains:



      ControlMaster auto
      ControlPath ~/.ssh/socket-%r@%h:%p

      Host hostname.example
      # TextMate rmate port
      RemoteForward :52698 localhost:52698


      When I make an initial connection to the host, it successfully creates the master socket file at ~/.ssh-lachlanhunt@hostname.example:22.



      But when I open a new terminal and attempt to make a second connection, I get this error:



      $ ssh hostname.example
      mux_client_forward: forwarding request failed: remote port forwarding failed for listen port 52698
      muxclient: master forward request failed
      ControlSocket /Users/lachlanhunt/.ssh/socket-lachlanhunt@hostname.example:22 already exists, disabling multiplexing
      Warning: remote port forwarding failed for listen port 52698


      But if I comment out the RemoteForward line in the config, it's able to successfully reuse the connection, making it connect faster. Is there any way I can configure ssh to support both multiplexed connections and enable the remote port forwarding, such that it only attempts to forward the port if it's the master connection?



      My system:



      • macOS Sierra 10.12.6

      • OpenSSH_7.4p1, LibreSSL 2.5.0









      share|improve this question














      My ~/.ssh/config contains:



      ControlMaster auto
      ControlPath ~/.ssh/socket-%r@%h:%p

      Host hostname.example
      # TextMate rmate port
      RemoteForward :52698 localhost:52698


      When I make an initial connection to the host, it successfully creates the master socket file at ~/.ssh-lachlanhunt@hostname.example:22.



      But when I open a new terminal and attempt to make a second connection, I get this error:



      $ ssh hostname.example
      mux_client_forward: forwarding request failed: remote port forwarding failed for listen port 52698
      muxclient: master forward request failed
      ControlSocket /Users/lachlanhunt/.ssh/socket-lachlanhunt@hostname.example:22 already exists, disabling multiplexing
      Warning: remote port forwarding failed for listen port 52698


      But if I comment out the RemoteForward line in the config, it's able to successfully reuse the connection, making it connect faster. Is there any way I can configure ssh to support both multiplexed connections and enable the remote port forwarding, such that it only attempts to forward the port if it's the master connection?



      My system:



      • macOS Sierra 10.12.6

      • OpenSSH_7.4p1, LibreSSL 2.5.0






      ssh port-forwarding






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Sep 19 '17 at 4:02









      Lachlan HuntLachlan Hunt

      1262




      1262




















          2 Answers
          2






          active

          oldest

          votes


















          2














          I figured out a solution. I use the Match section with the host and negated exec keywords to test for the hostname and the existence of the control socket file. If the file doesn't exist, then this is the master connection, so setup the port forwarding. Otherwise, this is a slave connection and the forwarding is skipped.



          ControlMaster auto
          ControlPath ~/.ssh/socket-%r@%h:%p

          Match host hostname1.example.com,hostname2.example.com !exec "[ -e ~/.ssh/socket-%r@%h:%p ]"
          # TextMate rmate port
          RemoteForward :52698 localhost:52698





          share|improve this answer























          • Good stuff! For people looking to create a LocalForward or DynamicForward, change !exec "[…]"into exec "[ ! -S ~/.ssh/socket-rmate ] && ln -sf ~/.ssh/socket-%r@%h:%p,rmate" so if you're already connected to hostname1, you'll be safe connecting to hostname2 since it's checking a shared socket thanks to the symlink. This uses bash/zsh Brace Expansion to more concisely create that link (ssh runs it in $SHELL). This must use -S rather than -e so it can operate on an existing-yet-broken symlink.

            – Adam Katz
            5 hours ago


















          0














          Here's another solution that does not depend on ControlMaster:



          Match host hostname1.example.com,hostname2.example.com !exec "nc -zw1 %h 52698"
          RemoteForward :52698 localhost:52698


          This also works for local port forwarding and SOCKS proxying:



          Match host hostname1.example.com,hostname2.example.com !exec "nc -zw1 localhost 52698"
          LocalForward 52698 remotehost:52698

          Match host hostname3,hostname4 !exec "nc -zw1 localhost 1050"
          DynamicForward 1050

          # Test for multiple ports
          Match host hostname5 !exec "nc -zw1 localhost 52698 && nc -zw1 localhost 1050"
          LocalForward 52698 remotehost:52698
          DynamicForward 1050


          These work by checking to see if the target port is opened. If not, it creates the desired port forwarding. netcat is a great tool for quick network tests and redirection. The -z option instructs netcat to just scan for whether a daemon is listening on the given port. -w1 says you should wait at most one second in the event your packets are ignored e.g. due to a DROP firewall policy.






          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%2f874335%2fssh-remoteforward-fails-with-shared-control-socket%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









            2














            I figured out a solution. I use the Match section with the host and negated exec keywords to test for the hostname and the existence of the control socket file. If the file doesn't exist, then this is the master connection, so setup the port forwarding. Otherwise, this is a slave connection and the forwarding is skipped.



            ControlMaster auto
            ControlPath ~/.ssh/socket-%r@%h:%p

            Match host hostname1.example.com,hostname2.example.com !exec "[ -e ~/.ssh/socket-%r@%h:%p ]"
            # TextMate rmate port
            RemoteForward :52698 localhost:52698





            share|improve this answer























            • Good stuff! For people looking to create a LocalForward or DynamicForward, change !exec "[…]"into exec "[ ! -S ~/.ssh/socket-rmate ] && ln -sf ~/.ssh/socket-%r@%h:%p,rmate" so if you're already connected to hostname1, you'll be safe connecting to hostname2 since it's checking a shared socket thanks to the symlink. This uses bash/zsh Brace Expansion to more concisely create that link (ssh runs it in $SHELL). This must use -S rather than -e so it can operate on an existing-yet-broken symlink.

              – Adam Katz
              5 hours ago















            2














            I figured out a solution. I use the Match section with the host and negated exec keywords to test for the hostname and the existence of the control socket file. If the file doesn't exist, then this is the master connection, so setup the port forwarding. Otherwise, this is a slave connection and the forwarding is skipped.



            ControlMaster auto
            ControlPath ~/.ssh/socket-%r@%h:%p

            Match host hostname1.example.com,hostname2.example.com !exec "[ -e ~/.ssh/socket-%r@%h:%p ]"
            # TextMate rmate port
            RemoteForward :52698 localhost:52698





            share|improve this answer























            • Good stuff! For people looking to create a LocalForward or DynamicForward, change !exec "[…]"into exec "[ ! -S ~/.ssh/socket-rmate ] && ln -sf ~/.ssh/socket-%r@%h:%p,rmate" so if you're already connected to hostname1, you'll be safe connecting to hostname2 since it's checking a shared socket thanks to the symlink. This uses bash/zsh Brace Expansion to more concisely create that link (ssh runs it in $SHELL). This must use -S rather than -e so it can operate on an existing-yet-broken symlink.

              – Adam Katz
              5 hours ago













            2












            2








            2







            I figured out a solution. I use the Match section with the host and negated exec keywords to test for the hostname and the existence of the control socket file. If the file doesn't exist, then this is the master connection, so setup the port forwarding. Otherwise, this is a slave connection and the forwarding is skipped.



            ControlMaster auto
            ControlPath ~/.ssh/socket-%r@%h:%p

            Match host hostname1.example.com,hostname2.example.com !exec "[ -e ~/.ssh/socket-%r@%h:%p ]"
            # TextMate rmate port
            RemoteForward :52698 localhost:52698





            share|improve this answer













            I figured out a solution. I use the Match section with the host and negated exec keywords to test for the hostname and the existence of the control socket file. If the file doesn't exist, then this is the master connection, so setup the port forwarding. Otherwise, this is a slave connection and the forwarding is skipped.



            ControlMaster auto
            ControlPath ~/.ssh/socket-%r@%h:%p

            Match host hostname1.example.com,hostname2.example.com !exec "[ -e ~/.ssh/socket-%r@%h:%p ]"
            # TextMate rmate port
            RemoteForward :52698 localhost:52698






            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered Sep 19 '17 at 9:15









            Lachlan HuntLachlan Hunt

            1262




            1262












            • Good stuff! For people looking to create a LocalForward or DynamicForward, change !exec "[…]"into exec "[ ! -S ~/.ssh/socket-rmate ] && ln -sf ~/.ssh/socket-%r@%h:%p,rmate" so if you're already connected to hostname1, you'll be safe connecting to hostname2 since it's checking a shared socket thanks to the symlink. This uses bash/zsh Brace Expansion to more concisely create that link (ssh runs it in $SHELL). This must use -S rather than -e so it can operate on an existing-yet-broken symlink.

              – Adam Katz
              5 hours ago

















            • Good stuff! For people looking to create a LocalForward or DynamicForward, change !exec "[…]"into exec "[ ! -S ~/.ssh/socket-rmate ] && ln -sf ~/.ssh/socket-%r@%h:%p,rmate" so if you're already connected to hostname1, you'll be safe connecting to hostname2 since it's checking a shared socket thanks to the symlink. This uses bash/zsh Brace Expansion to more concisely create that link (ssh runs it in $SHELL). This must use -S rather than -e so it can operate on an existing-yet-broken symlink.

              – Adam Katz
              5 hours ago
















            Good stuff! For people looking to create a LocalForward or DynamicForward, change !exec "[…]"into exec "[ ! -S ~/.ssh/socket-rmate ] && ln -sf ~/.ssh/socket-%r@%h:%p,rmate" so if you're already connected to hostname1, you'll be safe connecting to hostname2 since it's checking a shared socket thanks to the symlink. This uses bash/zsh Brace Expansion to more concisely create that link (ssh runs it in $SHELL). This must use -S rather than -e so it can operate on an existing-yet-broken symlink.

            – Adam Katz
            5 hours ago





            Good stuff! For people looking to create a LocalForward or DynamicForward, change !exec "[…]"into exec "[ ! -S ~/.ssh/socket-rmate ] && ln -sf ~/.ssh/socket-%r@%h:%p,rmate" so if you're already connected to hostname1, you'll be safe connecting to hostname2 since it's checking a shared socket thanks to the symlink. This uses bash/zsh Brace Expansion to more concisely create that link (ssh runs it in $SHELL). This must use -S rather than -e so it can operate on an existing-yet-broken symlink.

            – Adam Katz
            5 hours ago













            0














            Here's another solution that does not depend on ControlMaster:



            Match host hostname1.example.com,hostname2.example.com !exec "nc -zw1 %h 52698"
            RemoteForward :52698 localhost:52698


            This also works for local port forwarding and SOCKS proxying:



            Match host hostname1.example.com,hostname2.example.com !exec "nc -zw1 localhost 52698"
            LocalForward 52698 remotehost:52698

            Match host hostname3,hostname4 !exec "nc -zw1 localhost 1050"
            DynamicForward 1050

            # Test for multiple ports
            Match host hostname5 !exec "nc -zw1 localhost 52698 && nc -zw1 localhost 1050"
            LocalForward 52698 remotehost:52698
            DynamicForward 1050


            These work by checking to see if the target port is opened. If not, it creates the desired port forwarding. netcat is a great tool for quick network tests and redirection. The -z option instructs netcat to just scan for whether a daemon is listening on the given port. -w1 says you should wait at most one second in the event your packets are ignored e.g. due to a DROP firewall policy.






            share|improve this answer



























              0














              Here's another solution that does not depend on ControlMaster:



              Match host hostname1.example.com,hostname2.example.com !exec "nc -zw1 %h 52698"
              RemoteForward :52698 localhost:52698


              This also works for local port forwarding and SOCKS proxying:



              Match host hostname1.example.com,hostname2.example.com !exec "nc -zw1 localhost 52698"
              LocalForward 52698 remotehost:52698

              Match host hostname3,hostname4 !exec "nc -zw1 localhost 1050"
              DynamicForward 1050

              # Test for multiple ports
              Match host hostname5 !exec "nc -zw1 localhost 52698 && nc -zw1 localhost 1050"
              LocalForward 52698 remotehost:52698
              DynamicForward 1050


              These work by checking to see if the target port is opened. If not, it creates the desired port forwarding. netcat is a great tool for quick network tests and redirection. The -z option instructs netcat to just scan for whether a daemon is listening on the given port. -w1 says you should wait at most one second in the event your packets are ignored e.g. due to a DROP firewall policy.






              share|improve this answer

























                0












                0








                0







                Here's another solution that does not depend on ControlMaster:



                Match host hostname1.example.com,hostname2.example.com !exec "nc -zw1 %h 52698"
                RemoteForward :52698 localhost:52698


                This also works for local port forwarding and SOCKS proxying:



                Match host hostname1.example.com,hostname2.example.com !exec "nc -zw1 localhost 52698"
                LocalForward 52698 remotehost:52698

                Match host hostname3,hostname4 !exec "nc -zw1 localhost 1050"
                DynamicForward 1050

                # Test for multiple ports
                Match host hostname5 !exec "nc -zw1 localhost 52698 && nc -zw1 localhost 1050"
                LocalForward 52698 remotehost:52698
                DynamicForward 1050


                These work by checking to see if the target port is opened. If not, it creates the desired port forwarding. netcat is a great tool for quick network tests and redirection. The -z option instructs netcat to just scan for whether a daemon is listening on the given port. -w1 says you should wait at most one second in the event your packets are ignored e.g. due to a DROP firewall policy.






                share|improve this answer













                Here's another solution that does not depend on ControlMaster:



                Match host hostname1.example.com,hostname2.example.com !exec "nc -zw1 %h 52698"
                RemoteForward :52698 localhost:52698


                This also works for local port forwarding and SOCKS proxying:



                Match host hostname1.example.com,hostname2.example.com !exec "nc -zw1 localhost 52698"
                LocalForward 52698 remotehost:52698

                Match host hostname3,hostname4 !exec "nc -zw1 localhost 1050"
                DynamicForward 1050

                # Test for multiple ports
                Match host hostname5 !exec "nc -zw1 localhost 52698 && nc -zw1 localhost 1050"
                LocalForward 52698 remotehost:52698
                DynamicForward 1050


                These work by checking to see if the target port is opened. If not, it creates the desired port forwarding. netcat is a great tool for quick network tests and redirection. The -z option instructs netcat to just scan for whether a daemon is listening on the given port. -w1 says you should wait at most one second in the event your packets are ignored e.g. due to a DROP firewall policy.







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered 5 hours ago









                Adam KatzAdam Katz

                512415




                512415



























                    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%2f874335%2fssh-remoteforward-fails-with-shared-control-socket%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

                    How to make RAID controller rescan devices The 2019 Stack Overflow Developer Survey Results Are InLSI MegaRAID SAS 9261-8i: Disk isn't recognized after replacementHow to monitor the hard disk status behind Dell PERC H710 Raid Controller with CentOS 6?LSI MegaRAID - Recreate missing RAID 1 arrayext. 2-bay USB-Drive with RAID: btrfs RAID vs built-in RAIDInvalid SAS topologyDoes enabling JBOD mode on LSI based controllers affect existing logical disks/arrays?Why is there a shift between the WWN reported from the controller and the Linux system?Optimal RAID 6+0 Setup for 40+ 4TB DisksAccidental SAS cable removal

                    Куамањотепек (Чилапа де Алварез) Садржај Становништво Види још Референце Спољашње везе Мени за навигацију17°19′47″N 99°1′51″W / 17.32972° СГШ; 99.03083° ЗГД / 17.32972; -99.0308317°19′47″N 99°1′51″W / 17.32972° СГШ; 99.03083° ЗГД / 17.32972; -99.030838877656„Instituto Nacional de Estadística y Geografía”„The GeoNames geographical database”Мексичка насељапроширитиуу

                    Can the Right Ascension and Argument of Perigee of a spacecraft's orbit keep varying by themselves with time? The 2019 Stack Overflow Developer Survey Results Are InHow is the altitude of a satellite defined, given that the Earth is not spherical?Why do satellites appear to move faster when overhead and slower closer to the horizon?For the mathematical relationship between J2 (km^5/s^2) and dimensionless J2 - which one is derived from the other?Why is Nodal precession affected by the rotational period of the planet?Why is it so difficult to predict the exact reentry location and time of a very low earth orbit object?Why are low earth orbit satellites not visible from the same place all the time?Perifocal coordinates and the orbit equationHow feasible is the Moonspike mission?What was the typical perigee after a shuttle de-orbit burn?I am having trouble calculating my classic orbital elements and am at a loss on where to lookAm I supposed to modify the gravitational constant with scale and why do fps & time scale changes cause my orbit to break?How Local time of a sun synchronous orbit is related to Right ascension of ascending node?What is wrong with my orbit sim equations? How can I fix them?How to obtain the initial positions and velocities of an inclined orbit?