[Bug 4056] New: ForwardAgent $VAR always warns "Cannot forward agent socket path", and fails with ExitOnForwardFailure

bugzilla-daemon at mindrot.org bugzilla-daemon at mindrot.org
Sat Nov 14 01:17:00 AEDT 2026


https://bugzilla.mindrot.org/show_bug.cgi?id=4056

            Bug ID: 4056
           Summary: ForwardAgent $VAR always warns "Cannot forward agent
                    socket path", and fails with ExitOnForwardFailure
           Product: Portable OpenSSH
           Version: 10.6p1
          Hardware: Other
                OS: Linux
            Status: NEW
          Severity: minor
          Priority: P5
         Component: ssh
          Assignee: unassigned-bugs at mindrot.org
          Reporter: max at mwolf.dev

Disclaimer: AI-drafted, verified by me before filing. I answer
follow-ups.

When ForwardAgent names an environment variable ("ForwardAgent $VAR",
the form ssh_config(5) documents), ssh always prints

  Cannot forward agent socket path "$VAR": No such file or directory

even when the variable is set and points at a live agent socket. With
ExitOnForwardFailure=yes, ssh exits 255 instead of connecting. Without
it, forwarding still works: the variable is resolved later and the
agent is forwarded.

The existence check added for bz3264 (c3b16367, ssh.c around line 1507,
unchanged on master as of 268bdcb0c) runs
default_client_percent_dollar_expand() on the path, and that expands
only ${VAR}. A "$VAR" path stays literal, so stat() looks for a file
named "$VAR". The "$" form is resolved with getenv() further down
(around line 1789), after the check has already run.

The braced form ${VAR} passes the check, but it is not a way around
this: when the variable is unset, ssh refuses to connect ("Invalid
environment expansion"), while the "$VAR" form just turns forwarding
off.

Steps to reproduce, OpenSSH_10.6p1 (also seen with Ubuntu's 10.2p1),
any host, no config file:

  $ eval "$(ssh-agent -a /tmp/x/agent.sock)"; export
FWD=/tmp/x/agent.sock
  $ ssh -T -F /dev/null -o 'ForwardAgent $FWD' -G localhost >/dev/null
  Cannot forward agent socket path "$FWD": No such file or directory
  $ echo $?
  0
  $ ssh -T -F /dev/null -o 'ForwardAgent $FWD' -o
ExitOnForwardFailure=yes -G localhost >/dev/null
  Cannot forward agent socket path "$FWD": No such file or directory
  $ echo $?
  255
  $ ssh -T -F /dev/null -o 'ForwardAgent ${FWD}' -G localhost
>/dev/null
  $ echo $?
  0

-- 
You are receiving this mail because:
You are watching the assignee of the bug.


More information about the openssh-bugs mailing list