[Bug 4058] New: `ssh-copy-id -i file` fails when invoked though `dash` (also effects `zsh`)

bugzilla-daemon at mindrot.org bugzilla-daemon at mindrot.org
Tue Nov 17 12:24:10 AEDT 2026


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

            Bug ID: 4058
           Summary: `ssh-copy-id -i file` fails when invoked though `dash`
                    (also effects `zsh`)
           Product: Portable OpenSSH
           Version: 10.6p2
          Hardware: All
                OS: Linux
            Status: NEW
          Severity: minor
          Priority: P5
         Component: ssh-copy-id
          Assignee: unassigned-bugs at mindrot.org
          Reporter: tom at termux.dev

Created attachment 4027
  --> https://bugzilla.mindrot.org/attachment.cgi?id=4027&action=edit
xtrace of a failing `ssh-copy-id -i path` when running through `dash`

I'd like to report a bug regarding `ssh-copy-id`'s handling of the `-i
path/to/key_file` option when being run by `dash` (Debian Almquist
Shell).

I was first made aware of this problem by a user of Termux's[^1]
`openssh` package.
I have since been able to reproduce it on several desktop Linux systems
(Arch, Fedora 45).

When running `ssh-copy-id` via `dash` as the interpreter[^2],
adding `-i path/to/key_file` causes `ssh-copy-id` to error out with:

```
/bin/ssh-copy-id: ERROR: Too many arguments.  Expecting a target
hostname, got:

Usage: # [...]
```

I strongly suspect that this issue traces back to at least OpenSSH
9.9p1.
https://github.com/openssh/openssh-portable/commit/7fc9ccdce18841ebd0a97e31e43258512ab32a32

Following the `-x` trace (see attachments),
it seems like the `shift $((OPTIND-1))` at the end of the `while
getopts` loop discards an insufficient amount of arguments.
This works normally when invoked by `bash` or `loksh` (The Linux port
of the OpenBSH Korn Shell).
It does also fail when invoked through `zsh` (and `zsh --emulate sh`),
seemingly in the same way as when invoked through `dash`.

It appears that something in the parsing of `-i`'s argument
implicitly depends on Bash/Oksh's exact behavior in a way that breaks
Dash and Zsh's handling of the same statements.

I have not been able to puzzle out what could cause this mismatch in
behavior when interpreted through Bash/Loksh and Dash/Zsh.
But from what I can tell it must be something in this line range.
https://github.com/openssh/openssh-portable/blob/V_10_6_P2/contrib/ssh-copy-id#L139-L144

---

[^1]: Termux is a terminal emulator and Linux/UNIX application
packaging environment for Android.
I am one of the project's package maintainers, and among other things
maintain our Bash and OpenSSH packages.
https://en.wikipedia.org/wiki/Termux

[^2]: `dash` is the standard provider for `sh` on Termux.

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


More information about the openssh-bugs mailing list