SSH "ControlSocket already exists": multiplexing
When a client config turns on connection sharing, ssh tries to reuse or create
a control socket, a file on your own machine. A message that names a
ControlSocket, or a line about a unix_listener that
says Address already in use, means that step failed, so
multiplexing did not start or could not attach. The rest of the attempt may
still open an ordinary connection, or it may not.
This page describes standard OpenSSH behaviour. The commands are the usual ones, and wording, defaults and available options differ between versions and distributions. We did not run them on your system for this page.
What the message means
ControlSocket /home/you/.ssh/cm-you@server.example.com:22 already exists, disabling multiplexing
Connection sharing, often called multiplexing, lets later ssh commands to the
same host ride on one connection that an earlier command, the master, already
opened. The master listens on a Unix socket, a special file at the path set by
ControlPath, and the later commands talk to it. The path above is
only an example, since the file name and its folder come from your config.
The message says a file was already at the path ssh wanted for its own control socket, so ssh gave up being the master. Often a master from an earlier session is still running, or an old socket file was left behind after it was killed. A line like the one below can appear in the same situation, with a path that may carry an extra suffix, and its exact wording differs between versions:
unix_listener: cannot bind to path /home/you/.ssh/cm-example: Address already in use
After either message, ssh may go on and open the session as an ordinary
connection without sharing. Treat that as likely and not certain, and check
whether you did get a shell. The line that begins
Control socket connect(, where ssh could not connect to a socket
at a path, is the everyday connect failure and has
its own page. A
different message about the control socket, such as a path that is too long,
is a related problem. This page covers the two lines above.
This is a different message from the ones that sound alike, so confirm that first:
-
Address already in use on a local forward
is a line that starts with
bindand names a TCP address and a port, for a-Lor-Dforward. This page is about a socket file, not a TCP port. - Connection refused or timed out is about reaching a remote machine. A control socket is only on your side, so none of these messages come from the server.
-
A line that says a channel was
administratively prohibitedis a later message about the server refusing a forward after the tunnel was up. It is not a socket problem. - Bad configuration option means ssh did not accept a keyword in the config at all. Here ssh accepted the multiplexing settings and could not use the socket.
1. Read the path the message names
If the line gives a path, that is the file in question. Look at it:
ls -l /home/you/.ssh/cm-you@server.example.com:22
Use your own path. On most systems a socket shows s as the first
character of the listing. If the file is not there any more, the other session
may have just ended, and running the command again can be enough. The
ssh -v output reader can check a pasted log
for these lines. It runs in your browser and sends nothing.
2. See which settings ssh used
Once the client config is accepted, ssh -G prints the values ssh
would use for a host without connecting. Look for lines that start with
controlmaster, controlpath or
controlpersist, if they are present:
ssh -G myserver
controlpath is the file, and controlmaster says
whether this host is set to create or reuse one. A controlpersist
line, if there is one, is the setting that lets a master stay in the
background after the first session ends, which is a common reason an old
socket is still there. The
ssh -G output reader does not single out
any of these three lines in its reading, so read them in the raw output. The
path may contain tokens such as a host name or user, and
ssh -G shows the expanded form for the host you named.
Settings can come from a Host block in the config, from a
wildcard block, or from -o and -S on the command
line, so the printed value is the one to trust, and not the block you remember
writing.
3. Start fresh, or clear the stale master
There are two ways forward, and they suit different situations.
Open a session without sharing. If you only need a shell, tell ssh not to use a control socket for this one command:
ssh -o ControlPath=none user@server.example.com
That leaves the existing master and its socket as they are, which is the safer choice when other sessions are using it. Behaviour of the option can differ between versions, so if ssh still names a socket, check the config again.
Check the master, then stop it if it is stale. If you want sharing to work again, ask the master whether it is alive. This uses the same host name and settings as the original command, so ssh can work out the same path:
ssh -O check myserver
ssh -O exit myserver
-O check asks a running master to report, and
-O exit asks it to end. Ending a master can cut sessions and
forwards that still ride on it, so check what depends on it first. If
-O check says there is no master, or cannot connect, the file is
likely left over from a master that no longer runs. In that case, and only
after you have confirmed no ssh process still owns it, removing that one file
is usual. Make sure the path is the socket you looked at in step 1 and not
something else. Then run the original command again.
If it works, ssh should either start a master or attach to one without a
ControlSocket line. If the same message returns every time, look
for a script, a service or another login that starts a master on the same
path, or for two ControlPath values that resolve to one file.
If the machine is a RescueShell device
A path that starts from the device can avoid a public SSH port. The agent on the device keeps an outbound HTTPS connection to our relay, so reaching a shell does not depend on an inbound port on the device. See SSH behind a firewall without port forwarding.
A control socket is a file on your own computer, so clearing one changes nothing on a device. If a shell does not open once the agent is installed, see the shell does not open.
Try it on one device
The first device is free to try with no card, for 30 days from when it connects, not from when you sign up. Start a trial.