[Bug 2575] New: ssh-copy-id fails when it can not find any key file in ~/.ssh

bugzilla-daemon at bugzilla.mindrot.org bugzilla-daemon at bugzilla.mindrot.org
Mon May 30 18:54:09 AEST 2016


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

            Bug ID: 2575
           Summary: ssh-copy-id fails when it can not find any key file in
                    ~/.ssh
           Product: Portable OpenSSH
           Version: 7.2p1
          Hardware: All
                OS: Linux
            Status: NEW
          Severity: trivial
          Priority: P5
         Component: ssh-copy-id
          Assignee: unassigned-bugs at mindrot.org
          Reporter: jjelen at redhat.com

Today I run  ssh-copy-id  from a machine without any generated key (and
without any key in ssh-agent) and it failed hard with weird results:

    /usr/bin/ssh-copy-id: ERROR: failed to open ID file '/root/.pub':
No such file or directory
        (to install the contents of '/root/.pub' anyway, look at the -f
option)

It is caused by the false expectation, that there are some keys in
~/.ssh/ on the line 59:

    DEFAULT_PUB_ID_FILE="$HOME/$(cd "$HOME" ; ls -t .ssh/id*.pub
2>/dev/null | grep -v -- '-cert.pub$' | head -n 1)"

It sets

    + DEFAULT_PUB_ID_FILE=/root/

which passes the condition

    + '[' -r /root/ ']'

and the execution gets into the function   use_id_file()  unnoticed and
fails to open file

    /usr/bin/ssh-copy-id: line 87: /root/.pub: No such file or
directory'

Checking also if the file is regular file should solve the issue.
Failing earlier is probably not a good idea, because we can still use 
ssh-agent  keys (remains working).


diff --git a/contrib/ssh-copy-id b/contrib/ssh-copy-id
index bef5c95..f750e70 100644
--- a/contrib/ssh-copy-id
+++ b/contrib/ssh-copy-id
@@ -189,7 +189,8 @@ SSH_OPTS="${SSH_OPTS:+$SSH_OPTS }'$(quote
"$USER_HOST")'"
 # and populate "$@" for later use (only way to get proper quoting of
options)
 eval set -- "$SSH_OPTS"

-if [ -z "$(eval $GET_ID)" ] && [ -r
"${PUB_ID_FILE:=$DEFAULT_PUB_ID_FILE}" ] ; then
+if [ -z "$(eval $GET_ID)" ] && [ -r
"${PUB_ID_FILE:=$DEFAULT_PUB_ID_FILE}" ] \
+    && [ -f "$PUB_ID_FILE" ] ; then
   use_id_file "$PUB_ID_FILE"
 fi

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


More information about the openssh-bugs mailing list