Bug 3158

Summary: ssh-copy-id raises "expr: syntax error" when double-hyphen is passed ("--")
Product: Portable OpenSSH Reporter: rf
Component: ssh-copy-idAssignee: Assigned to nobody <unassigned-bugs>
Status: CLOSED FIXED    
Severity: minor CC: phil
Priority: P5    
Version: 8.2p1   
Hardware: All   
OS: Linux   

Description rf 2020-05-04 07:51:19 AEST
Assuming an identity file exists at ~/.ssh/id_rsa.pub, the following command, which adds a preventative double-dash ("--"):

    ssh-copy-id -i ~/.ssh/id_rsa.pub -- remote-server

will result in the following error:

    expr: syntax error: unexpected argument ā€˜[-]i’

The error is non-fatal, but it may be confusing to users.

I suspect this is caused by line 110:

    [ "${SEEN_OPT_I}" ] && expr "$1" : "[-]i" >/dev/null && {

Here, "$1" is passed to expr without being validated, so if $1 is "--" as shown in the command above, this will confuse expr.  I think expr should be called with "--" to prevent this:

    [ "${SEEN_OPT_I}" ] && expr -- "$1" : "[-]i" >/dev/null && {
Comment 1 Philip Hands 2020-09-17 16:25:04 AEST
ssh-copy-id has switched to using getopts for this, rather than the previous hand-rolled option handling, so I beleive that once that version is included in openssh this problem will be solved.

Perhaps you'd be so kind as to check that -- you can find the latest version here:

  https://gitlab.com/phil_hands/ssh-copy-id

Cheers, Phil.
Comment 2 rf 2020-09-20 10:17:51 AEST
The issue appears to be fixe din the new ssh-copy-id. Thanks!
Comment 3 Damien Miller 2021-03-04 09:52:21 AEDT
close bugs that were resolved in OpenSSH 8.5 release cycle