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
Thanks for the report, and sorry for taking so long to get round to it. Here's the commit that fixes this: http://git.hands.com/?p=ssh-copy-id.git;a=commitdiff;h=b32a55c8eb4995ef56880682d5ff2eeb9856928d In which I decided to rather make sure that DEFAULT_PUB_ID_FILE remains unset in this case, and then deal with that case. My latest version incorporating that change is here: http://git.hands.com/ssh-copy-id which should work for you, and will hopefully make it's way into OpenSSH in the not too distant future. Cheers, Phil.
Thanks. It works as expected. Damien, Darren, can we expect this fix in 7.4? This was working before with openssh-6.6p1 (for example) but current master is failing.
Close all resolved bugs after release of OpenSSH 7.7.