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;
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
add a comment |
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
add a comment |
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
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
ssh port-forwarding
asked Sep 19 '17 at 4:02
Lachlan HuntLachlan Hunt
1262
1262
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
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
Good stuff! For people looking to create a LocalForward or DynamicForward, change!exec "[…]"
intoexec "[ ! -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
add a comment |
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.
add a comment |
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
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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
Good stuff! For people looking to create a LocalForward or DynamicForward, change!exec "[…]"
intoexec "[ ! -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
add a comment |
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
Good stuff! For people looking to create a LocalForward or DynamicForward, change!exec "[…]"
intoexec "[ ! -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
add a comment |
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
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
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 "[…]"
intoexec "[ ! -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
add a comment |
Good stuff! For people looking to create a LocalForward or DynamicForward, change!exec "[…]"
intoexec "[ ! -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
add a comment |
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.
add a comment |
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.
add a comment |
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.
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.
answered 5 hours ago
Adam KatzAdam Katz
512415
512415
add a comment |
add a comment |
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.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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