Strovent SystemsSign in
Reference

SSH "ControlPath too long" and other connection-sharing errors

ControlPath too long and too long for Unix domain socket mean the socket path is over the system limit. Use a short folder and %C. Other mux errors too.

These messages come from OpenSSH connection sharing (ControlMaster, ControlPath), where later sessions reuse a master connection through a socket file. How sharing works is in SSH ControlMaster: reuse one connection with ControlPath and ControlPersist.

"ControlPath too long" and "too long for Unix domain socket"

ControlPath too long ('/home/user1/.ansible/cp/...' >= 108 bytes)
unix_listener: path "/home/user1/.ssh/cm/[email protected]" too long for Unix domain socket

The control socket is a Unix domain socket, and its path must fit in a fixed-size field: 108 bytes on Linux, 104 on OpenBSD. Other systems have their own limit.

  • ControlPath too long (... >= 108 bytes) means the path itself is too long. ssh stops before it connects.
  • unix_listener: ... too long for Unix domain socket appears when ssh is about to become the master. It first creates the socket under a temporary name, your path plus a dot and 16 random characters, then renames it. So a path 17 characters short of the limit still fails. This happens after the login has succeeded, and ssh then exits, which is why tools such as Ansible report a failure right after a good login.

Long host names, long user names and deep home folders all make the path longer. The fix is a short path:

mkdir -m 700 ~/.ssh/cm
Host *
    ControlPath ~/.ssh/cm/%C

%C is a fixed-length hash of the local host, remote host, port, user and jump host, so the length no longer depends on the names. If your home folder path is itself long, use a short folder elsewhere that only you can write to. A tool that passes its own -o ControlPath on the command line, as Ansible does, overrides your config file, because command-line options take precedence. Shorten the path in that tool's settings instead.

"Session open refused by peer"

mux_client_request_session: session request failed: Session open refused by peer
ControlSocket /home/user1/.ssh/cm/0f3a... already exists, disabling multiplexing

The master is running, but the server refused one more session on its connection. The usual cause is the server's MaxSessions limit in sshd_config, which defaults to 10 sessions per connection; MaxSessions 1 turns sharing off. Each shell, command and sftp running through the master counts.

ssh then makes a separate connection of its own, which is where the second line comes from, and may ask you to log in again. To fix it, close sessions you are not using, raise MaxSessions on a server you manage, or give jobs that run many sessions in parallel their own ControlPath.

"ControlSocket ... already exists, disabling multiplexing"

On its own, this line means ssh wanted to become the master, but a socket with that name already exists, for example because two connections to the same host started at the same moment and the other one won. This connection still works, just without sharing. With ControlMaster yes, it appears every time a master is already running; auto uses the running master instead.

"Control socket connect(...)"

Control socket connect(/home/user1/.ssh/cm/0f3a...): No such file or directory
Control socket connect(/home/user1/.ssh/cm/0f3a...): Connection refused
  • No such file or directory from ssh -O check or ssh -O exit means no master is running for that host, user and port.
  • Connection refused means the socket file is left over from a master that ended without removing it. With ControlMaster auto, ssh removes such a stale socket by itself and connects normally. Otherwise delete the file named in the message.

"No ControlPath specified for "-O" command"

ssh -O needs to know which socket to talk to. Add ControlPath for that host in ~/.ssh/config, or give the path with -S.

Sources

Spotted a mistake? Email [email protected].