ssh-copy-id no newline bug
erjoalgo at gmail.com
Sun Mar 20 07:53:32 AEDT 2016
When editing ~/.ssh/authorized_keys manually, sometimes users forget
to add a newline at the end of the file, causing the next ssh-copy-id
call to append a new key to an existing key, invalidating both keys.
This can be fixed by simply adding a newline before appending the key.
Something like this change to
openssh-source/openssh-6.7p1/contrib/ssh-copy-id might work:
# Assuming that the remote host treats ~/.ssh/authorized_keys as one
[ "$DRY_RUN" ] || printf '%s\n' "$NEW_IDS" | ssh "$@" "
umask 077 ;
mkdir -p .ssh && \
echo >> .ssh/authorized_keys && \
cat >> .ssh/authorized_keys || exit 1 ;
if type restorecon >/dev/null 2>&1 ; then restorecon -F .ssh
.ssh/authorized_keys ; fi" \
|| exit 1
ADDED=$(printf '%s\n' "$NEW_IDS" | wc -l)
More information about the openssh-unix-dev