86f52d4
From 1a52b2d612b1d0c2a15dfcdc8da560704909ec72 Mon Sep 17 00:00:00 2001
86f52d4
From: Philip Hands <phil@hands.com>
86f52d4
Date: Sat, 27 Jul 2013 14:16:52 +0100
86f52d4
Subject: [PATCH] echo --> printf "%s: ERROR... (for consistency)
86f52d4
86f52d4
---
86f52d4
 ssh-copy-id | 2 +-
86f52d4
 1 file changed, 1 insertion(+), 1 deletion(-)
86f52d4
86f52d4
diff --git $1/contrib/ssh-copy-id $1/contrib/ssh-copy-id
86f52d4
index ae88e99..516b87f 100755
86f52d4
--- $1/contrib/ssh-copy-id
86f52d4
+++ $1/contrib/ssh-copy-id
86f52d4
@@ -200,7 +200,7 @@ populate_new_ids() {
86f52d4
   umask 0177
86f52d4
   local L_TMP_ID_FILE=$(mktemp ~/.ssh/ssh-copy-id_id.XXXXXXXXXX)
86f52d4
   if test $? -ne 0 || test "x$L_TMP_ID_FILE" = "x" ; then
86f52d4
-    echo "mktemp failed" 1>&2
86f52d4
+    printf '%s: ERROR: mktemp failed\n' "$0" >&2
86f52d4
     exit 1
86f52d4
   fi
86f52d4
   trap "rm -f $L_TMP_ID_FILE ${L_TMP_ID_FILE}.pub" EXIT TERM INT QUIT
86f52d4
-- 
86f52d4
1.9.1
86f52d4
86f52d4
86f52d4
86f52d4
From baebbb9e18e4a1af7554d939710eacb665a24b68 Mon Sep 17 00:00:00 2001
86f52d4
From: Philip Hands <phil@hands.com>
86f52d4
Date: Wed, 25 Nov 2015 17:05:39 +0100
86f52d4
Subject: [PATCH] Deal with remote user shell being e.g. tcsh (fixes: 2206)
86f52d4
86f52d4
as suggested by Jakub Jelen <jjelen@redhat.com>
86f52d4
---
86f52d4
 ssh-copy-id | 6 ++----
86f52d4
 1 file changed, 2 insertions(+), 4 deletions(-)
86f52d4
86f52d4
diff --git $1/contrib/ssh-copy-id $1/contrib/ssh-copy-id
86f52d4
index 516b87f..6a0447a 100755
86f52d4
--- $1/contrib/ssh-copy-id
86f52d4
+++ $1/contrib/ssh-copy-id
86f52d4
@@ -269,10 +269,8 @@ case "$REMOTE_VERSION" in
86f52d4
   *)
86f52d4
     # Assuming that the remote host treats ~/.ssh/authorized_keys as one might expect
86f52d4
     populate_new_ids 0
86f52d4
-    [ "$DRY_RUN" ] || printf '%s\n' "$NEW_IDS" | ssh "$@" "
86f52d4
-		umask 077 ;
86f52d4
-		mkdir -p .ssh && cat >> .ssh/authorized_keys || exit 1 ;
86f52d4
-		if type restorecon >/dev/null 2>&1 ; then restorecon -F .ssh .ssh/authorized_keys ; fi" \
86f52d4
+    [ "$DRY_RUN" ] || printf '%s\n' "$NEW_IDS" | \
86f52d4
+      ssh "$@" "exec sh -c 'umask 077 ; mkdir -p .ssh && cat >> .ssh/authorized_keys || exit 1 ; if type restorecon >/dev/null 2>&1 ; then restorecon -F .ssh .ssh/authorized_keys ; fi'" \
86f52d4
       || exit 1
86f52d4
     ADDED=$(printf '%s\n' "$NEW_IDS" | wc -l)
86f52d4
     ;;
86f52d4
-- 
86f52d4
1.9.1
86f52d4
86f52d4
86f52d4
86f52d4
From 35f05e39cda8670b3f6797330a3e521fda509a4c Mon Sep 17 00:00:00 2001
86f52d4
From: Philip Hands <phil@hands.com>
86f52d4
Date: Wed, 25 Nov 2015 21:14:00 +0100
86f52d4
Subject: [PATCH] set LogLevel to ensure that it's not set to 'None' (closes:
86f52d4
 2214)
86f52d4
86f52d4
As pointed out by  Sami Haahtinen <sami@badwolf.fi>,
86f52d4
the LogLevel is set to 'None' we'll not get the
86f52d4
Permission Denied we're looking for.
86f52d4
---
86f52d4
 ssh-copy-id | 1 +
86f52d4
 1 file changed, 1 insertion(+)
86f52d4
86f52d4
diff --git $1/contrib/ssh-copy-id $1/contrib/ssh-copy-id
86f52d4
index 6a0447a..70d3866 100755
86f52d4
--- $1/contrib/ssh-copy-id
86f52d4
+++ $1/contrib/ssh-copy-id
86f52d4
@@ -215,6 +215,7 @@ populate_new_ids() {
86f52d4
         # The point being that if file based, ssh needs the private key, which it cannot
86f52d4
         # find if only given the contents of the .pub file in an unrelated tmpfile
86f52d4
         ssh -i "${PRIV_ID_FILE:-$L_TMP_ID_FILE}" \
86f52d4
+            -o LogLevel=INFO \
86f52d4
             -o PreferredAuthentications=publickey \
86f52d4
             -o IdentitiesOnly=yes "$@" exit 2>$L_TMP_ID_FILE.stderr 
86f52d4
         if [ "$?" = "$L_SUCCESS" ] ; then
86f52d4
-- 
86f52d4
1.9.1
86f52d4
86f52d4
86f52d4
86f52d4
From e129c91dc474d73671304403fafda785df440105 Mon Sep 17 00:00:00 2001
86f52d4
From: Philip Hands <phil@hands.com>
86f52d4
Date: Wed, 25 Nov 2015 22:30:43 +0100
86f52d4
Subject: [PATCH] set ControlPath=none (closes: 2488)
86f52d4
MIME-Version: 1.0
86f52d4
Content-Type: text/plain; charset=utf8
86f52d4
Content-Transfer-Encoding: 8bit
86f52d4
86f52d4
Thanks to  Salvador Fandiño <sfandino@yahoo.com> for the patch
86f52d4
This seems to be the same problem as described in 2195
86f52d4
---
86f52d4
 ssh-copy-id | 3 ++-
86f52d4
 1 file changed, 2 insertions(+), 1 deletion(-)
86f52d4
86f52d4
diff --git $1/contrib/ssh-copy-id $1/contrib/ssh-copy-id
86f52d4
index 70d3866..7df7fad 100755
86f52d4
--- $1/contrib/ssh-copy-id
86f52d4
+++ $1/contrib/ssh-copy-id
86f52d4
@@ -215,6 +215,7 @@ populate_new_ids() {
86f52d4
         # The point being that if file based, ssh needs the private key, which it cannot
86f52d4
         # find if only given the contents of the .pub file in an unrelated tmpfile
86f52d4
         ssh -i "${PRIV_ID_FILE:-$L_TMP_ID_FILE}" \
86f52d4
+            -o ControlPath=none \
86f52d4
             -o LogLevel=INFO \
86f52d4
             -o PreferredAuthentications=publickey \
86f52d4
             -o IdentitiesOnly=yes "$@" exit 2>$L_TMP_ID_FILE.stderr 
86f52d4
@@ -244,7 +245,7 @@ populate_new_ids() {
86f52d4
   printf '%s: INFO: %d key(s) remain to be installed -- if you are prompted now it is to install the new keys\n' "$0" "$(printf '%s\n' "$NEW_IDS" | wc -l)" >&2
86f52d4
 }
86f52d4
 
86f52d4
-REMOTE_VERSION=$(ssh -v -o PreferredAuthentications=',' "$@" 2>&1 |
86f52d4
+REMOTE_VERSION=$(ssh -v -o PreferredAuthentications=',' -o ControlPath=none "$@" 2>&1 |
86f52d4
                  sed -ne 's/.*remote software version //p')
86f52d4
 
86f52d4
 case "$REMOTE_VERSION" in
86f52d4
-- 
86f52d4
1.9.1
86f52d4
86f52d4
86f52d4
86f52d4
From 6fa6f1e3dbec32636e77d01228ceecfa3851c7e8 Mon Sep 17 00:00:00 2001
86f52d4
From: Philip Hands <phil@hands.com>
86f52d4
Date: Wed, 25 Nov 2015 23:24:13 +0100
86f52d4
Subject: [PATCH] add -f (forced) option to install keys unconditionally
86f52d4
 (closes: 2110)
86f52d4
86f52d4
Thanks for the patch from Petr Lautrbach <plautrba@redhat.com>
86f52d4
which inspired this.
86f52d4
---
86f52d4
 ssh-copy-id   | 15 +++++++++++++--
86f52d4
 ssh-copy-id.1 |  5 +++++
86f52d4
 2 files changed, 18 insertions(+), 2 deletions(-)
86f52d4
86f52d4
diff --git $1/contrib/ssh-copy-id $1/contrib/ssh-copy-id
86f52d4
index 7df7fad..3121171 100755
86f52d4
--- $1/contrib/ssh-copy-id
86f52d4
+++ $1/contrib/ssh-copy-id
86f52d4
@@ -59,7 +59,10 @@ fi
86f52d4
 DEFAULT_PUB_ID_FILE=$(ls -t ${HOME}/.ssh/id*.pub 2>/dev/null | grep -v -- '-cert.pub$' | head -n 1)
86f52d4
 
86f52d4
 usage () {
86f52d4
-  printf 'Usage: %s [-h|-?|-n] [-i [identity_file]] [-p port] [[-o <ssh -o options>] ...] [user@]hostname\n' "$0" >&2
86f52d4
+  printf 'Usage: %s [-h|-?|-f|-n] [-i [identity_file]] [-p port] [[-o <ssh -o options>] ...] [user@]hostname\n' "$0" >&2
86f52d4
+  printf '\t-f: force mode -- copy keys without trying to check if they are already installed\n' >&2
86f52d4
+  printf '\t-n: dry run    -- no keys are actually copied\n' >&2
86f52d4
+  printf '\t-h|-?: print this help\n' >&2
86f52d4
   exit 1
86f52d4
 }
86f52d4
 
86f52d4
@@ -121,7 +124,7 @@ do
86f52d4
       }
86f52d4
       shift
86f52d4
       ;;
86f52d4
-    -n|-h|-\?)
86f52d4
+    -f|-n|-h|-\?)
86f52d4
       OPT="$1"
86f52d4
       OPTARG=
86f52d4
       shift
86f52d4
@@ -154,6 +157,9 @@ do
86f52d4
     -o|-p)
86f52d4
       SSH_OPTS="${SSH_OPTS:+$SSH_OPTS }$OPT '$(quote "$OPTARG")'"
86f52d4
       ;;
86f52d4
+    -f)
86f52d4
+      FORCED=1
86f52d4
+      ;;
86f52d4
     -n)
86f52d4
       DRY_RUN=1
86f52d4
       ;;
86f52d4
@@ -194,6 +200,11 @@ fi
86f52d4
 populate_new_ids() {
86f52d4
   local L_SUCCESS="$1"
86f52d4
 
86f52d4
+  if [ "$FORCED" ] ; then
86f52d4
+    NEW_IDS=$(eval $GET_ID)
86f52d4
+    return
86f52d4
+  fi
86f52d4
+
86f52d4
   # repopulate "$@" inside this function 
86f52d4
   eval set -- "$SSH_OPTS"
86f52d4
 
86f52d4
diff --git $1/contrib/ssh-copy-id.1 $1/contrib/ssh-copy-id.1
86f52d4
index 67a59e4..8850cce 100644
86f52d4
--- $1/contrib/ssh-copy-id.1
86f52d4
+++ $1/contrib/ssh-copy-id.1
86f52d4
@@ -29,6 +29,7 @@ THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
86f52d4
 .Nd use locally available keys to authorise logins on a remote machine
86f52d4
 .Sh SYNOPSIS
86f52d4
 .Nm
86f52d4
+.Op Fl f
86f52d4
 .Op Fl n
86f52d4
 .Op Fl i Op Ar identity_file
86f52d4
 .Op Fl p Ar port
86f52d4
@@ -76,6 +77,10 @@ is used.
86f52d4
 Note that this can be used to ensure that the keys copied have the
86f52d4
 comment one prefers and/or extra options applied, by ensuring that the
86f52d4
 key file has these set as preferred before the copy is attempted.
86f52d4
+.It Fl f
86f52d4
+Forced mode: doesn't check if the keys are present on the remote server.
86f52d4
+This means that it does not need the private key.  Of course, this can result
86f52d4
+in more than one copy of the key being installed on the remote system.
86f52d4
 .It Fl n
86f52d4
 do a dry-run.  Instead of installing keys on the remote system simply
86f52d4
 prints the key(s) that would have been installed.
86f52d4
-- 
86f52d4
1.9.1
86f52d4
86f52d4
86f52d4
86f52d4
From ab185eea5a03cdd846c909d83e5dd0a07a44fb54 Mon Sep 17 00:00:00 2001
86f52d4
From: Philip Hands <phil@hands.com>
86f52d4
Date: Wed, 25 Nov 2015 23:47:06 +0100
86f52d4
Subject: [PATCH] deal with #2331 by suggesting the use of the -f option
86f52d4
86f52d4
---
86f52d4
 ssh-copy-id | 3 ++-
86f52d4
 1 file changed, 2 insertions(+), 1 deletion(-)
86f52d4
86f52d4
diff --git $1/contrib/ssh-copy-id $1/contrib/ssh-copy-id
86f52d4
index 3121171..8666cea 100755
86f52d4
--- $1/contrib/ssh-copy-id
86f52d4
+++ $1/contrib/ssh-copy-id
86f52d4
@@ -250,7 +250,8 @@ populate_new_ids() {
86f52d4
     exit 1
86f52d4
   fi
86f52d4
   if [ -z "$NEW_IDS" ] ; then
86f52d4
-    printf '\n%s: WARNING: All keys were skipped because they already exist on the remote system.\n\n' "$0" >&2
86f52d4
+    printf '\n%s: WARNING: All keys were skipped because they already exist on the remote system.\n' "$0" >&2
86f52d4
+    printf '\t\t(if you think this is a mistake, you may want to use -f option)\n\n' "$0" >&2
86f52d4
     exit 0
86f52d4
   fi
86f52d4
   printf '%s: INFO: %d key(s) remain to be installed -- if you are prompted now it is to install the new keys\n' "$0" "$(printf '%s\n' "$NEW_IDS" | wc -l)" >&2
86f52d4
-- 
86f52d4
1.9.1
86f52d4
86f52d4
86f52d4
86f52d4
From de78897ada50ed12f4b0c9faa6e935ce82ee49a6 Mon Sep 17 00:00:00 2001
86f52d4
From: Philip Hands <phil@hands.com>
86f52d4
Date: Thu, 26 Nov 2015 00:25:56 +0100
86f52d4
Subject: [PATCH] handle keys with missing trailing newline (closes: 2350)
86f52d4
86f52d4
---
86f52d4
 ssh-copy-id | 2 +-
86f52d4
 1 file changed, 1 insertion(+), 1 deletion(-)
86f52d4
86f52d4
diff --git $1/contrib/ssh-copy-id $1/contrib/ssh-copy-id
86f52d4
index 8666cea..362b49b 100755
86f52d4
--- $1/contrib/ssh-copy-id
86f52d4
+++ $1/contrib/ssh-copy-id
86f52d4
@@ -218,7 +218,7 @@ populate_new_ids() {
86f52d4
   printf '%s: INFO: attempting to log in with the new key(s), to filter out any that are already installed\n' "$0" >&2
86f52d4
   NEW_IDS=$(
86f52d4
     eval $GET_ID | {
86f52d4
-      while read ID ; do
86f52d4
+      while read ID || [ "$ID" ] ; do
86f52d4
         printf '%s\n' "$ID" > $L_TMP_ID_FILE
86f52d4
 
86f52d4
         # the next line assumes $PRIV_ID_FILE only set if using a single id file - this
86f52d4
-- 
86f52d4
1.9.1
86f52d4
86f52d4
86f52d4
86f52d4
From 6b903ab99a3f0107bb0dbde748a4372033bab00c Mon Sep 17 00:00:00 2001
86f52d4
From: Philip Hands <phil@hands.com>
86f52d4
Date: Thu, 26 Nov 2015 00:36:09 +0100
86f52d4
Subject: [PATCH] add a cd to ensure we're in the remote's home directory
86f52d4
 (closes: 2349)
86f52d4
86f52d4
---
86f52d4
 ssh-copy-id | 2 +-
86f52d4
 1 file changed, 1 insertion(+), 1 deletion(-)
86f52d4
86f52d4
diff --git $1/contrib/ssh-copy-id $1/contrib/ssh-copy-id
86f52d4
index 362b49b..2932936 100755
86f52d4
--- $1/contrib/ssh-copy-id
86f52d4
+++ $1/contrib/ssh-copy-id
86f52d4
@@ -284,7 +284,7 @@ case "$REMOTE_VERSION" in
86f52d4
     # Assuming that the remote host treats ~/.ssh/authorized_keys as one might expect
86f52d4
     populate_new_ids 0
86f52d4
     [ "$DRY_RUN" ] || printf '%s\n' "$NEW_IDS" | \
86f52d4
-      ssh "$@" "exec sh -c 'umask 077 ; mkdir -p .ssh && cat >> .ssh/authorized_keys || exit 1 ; if type restorecon >/dev/null 2>&1 ; then restorecon -F .ssh .ssh/authorized_keys ; fi'" \
86f52d4
+      ssh "$@" "exec sh -c 'cd ; umask 077 ; mkdir -p .ssh && cat >> .ssh/authorized_keys || exit 1 ; if type restorecon >/dev/null 2>&1 ; then restorecon -F .ssh .ssh/authorized_keys ; fi'" \
86f52d4
       || exit 1
86f52d4
     ADDED=$(printf '%s\n' "$NEW_IDS" | wc -l)
86f52d4
     ;;
86f52d4
-- 
86f52d4
1.9.1
86f52d4
86f52d4
86f52d4
86f52d4
From 441892cbf4ff96fd96908582b8170f51890b5deb Mon Sep 17 00:00:00 2001
86f52d4
From: Philip Hands <phil@hands.com>
86f52d4
Date: Sat, 28 Nov 2015 14:42:36 +0100
86f52d4
Subject: [PATCH] add comment about why the ugly one-line remote command is as
86f52d4
 it is
86f52d4
86f52d4
In case anyone looks here for the details:
86f52d4
 * tcsh doesn't support multi-line strings,
86f52d4
   which is why it's a one-liner.
86f52d4
 * tcsh doesn't do 2>&1, and fish doesn't do
86f52d4
   'command || command' which is why we're runnig this under
86f52d4
   sh (which is very likely to be a POSIX shell on any vaguely
86f52d4
   Unix-like system)
86f52d4
 * The 'cd' is there to make sure we're in the home dir, because
86f52d4
   there was a bug report about having a cd in ~/.bashrc that resulted
86f52d4
   in a .ssh being created elsewhere.
86f52d4
 * the 'exec' ensures that we're not relying on anything beyond the
86f52d4
   (hopefully POSIX) shell that's available as 'sh' on the remote system
86f52d4
---
86f52d4
 ssh-copy-id | 1 +
86f52d4
 1 file changed, 1 insertion(+)
86f52d4
86f52d4
diff --git $1/contrib/ssh-copy-id $1/contrib/ssh-copy-id
86f52d4
index 2932936..04c03eb 100755
86f52d4
--- $1/contrib/ssh-copy-id
86f52d4
+++ $1/contrib/ssh-copy-id
86f52d4
@@ -283,6 +283,7 @@ case "$REMOTE_VERSION" in
86f52d4
   *)
86f52d4
     # Assuming that the remote host treats ~/.ssh/authorized_keys as one might expect
86f52d4
     populate_new_ids 0
86f52d4
+    # in ssh below - to defend against quirky remote shells: use 'exec sh -c' to get POSIX; 'cd' to be at $HOME; and all on one line, because tcsh.
86f52d4
     [ "$DRY_RUN" ] || printf '%s\n' "$NEW_IDS" | \
86f52d4
       ssh "$@" "exec sh -c 'cd ; umask 077 ; mkdir -p .ssh && cat >> .ssh/authorized_keys || exit 1 ; if type restorecon >/dev/null 2>&1 ; then restorecon -F .ssh .ssh/authorized_keys ; fi'" \
86f52d4
       || exit 1
86f52d4
-- 
86f52d4
1.9.1
86f52d4
86f52d4
86f52d4
86f52d4
From 8b59b122d321b97badd15c41e1a22863aa922a02 Mon Sep 17 00:00:00 2001
86f52d4
From: Philip Hands <phil@hands.com>
86f52d4
Date: Sat, 28 Nov 2015 14:46:47 +0100
86f52d4
Subject: [PATCH] with '-f' there's no need to have access to the private key
86f52d4
86f52d4
---
86f52d4
 ssh-copy-id | 2 +-
86f52d4
 1 file changed, 1 insertion(+), 1 deletion(-)
86f52d4
86f52d4
diff --git $1/contrib/ssh-copy-id $1/contrib/ssh-copy-id
86f52d4
index 04c03eb..d3ff83b 100755
86f52d4
--- $1/contrib/ssh-copy-id
86f52d4
+++ $1/contrib/ssh-copy-id
86f52d4
@@ -80,7 +80,7 @@ use_id_file() {
86f52d4
     PUB_ID_FILE="$L_ID_FILE.pub"
86f52d4
   fi
86f52d4
 
86f52d4
-  PRIV_ID_FILE=$(dirname "$PUB_ID_FILE")/$(basename "$PUB_ID_FILE" .pub)
86f52d4
+  [ "$FORCED" ] || PRIV_ID_FILE=$(dirname "$PUB_ID_FILE")/$(basename "$PUB_ID_FILE" .pub)
86f52d4
 
86f52d4
   # check that the files are readable
86f52d4
   for f in $PUB_ID_FILE $PRIV_ID_FILE ; do
86f52d4
-- 
86f52d4
1.9.1
86f52d4
86f52d4
86f52d4
86f52d4
From 1b931894de0614099255244be789ad097fd0948a Mon Sep 17 00:00:00 2001
86f52d4
From: Philip Hands <phil@hands.com>
86f52d4
Date: Sat, 28 Nov 2015 14:47:35 +0100
86f52d4
Subject: [PATCH] if the private key is missing, point out that '-f' might be
86f52d4
 what's needed
86f52d4
86f52d4
---
86f52d4
 ssh-copy-id | 4 +++-
86f52d4
 1 file changed, 3 insertions(+), 1 deletion(-)
86f52d4
86f52d4
diff --git $1/contrib/ssh-copy-id $1/contrib/ssh-copy-id
86f52d4
index d3ff83b..f0b01aa 100755
86f52d4
--- $1/contrib/ssh-copy-id
86f52d4
+++ $1/contrib/ssh-copy-id
86f52d4
@@ -85,7 +85,9 @@ use_id_file() {
86f52d4
   # check that the files are readable
86f52d4
   for f in $PUB_ID_FILE $PRIV_ID_FILE ; do
86f52d4
     ErrMSG=$( { : < $f ; } 2>&1 ) || {
86f52d4
-      printf "\n%s: ERROR: failed to open ID file '%s': %s\n\n" "$0" "$f" "$(printf "%s\n" "$ErrMSG" | sed -e 's/.*: *//')"
86f52d4
+      local L_PRIVMSG=""
86f52d4
+      [ "$f" = "$PRIV_ID_FILE" ] && L_PRIVMSG="	(to install the contents of '$PUB_ID_FILE' anyway, look at the -f option)"
86f52d4
+      printf "\n%s: ERROR: failed to open ID file '%s': %s\n" "$0" "$f" "$(printf "%s\n%s\n" "$ErrMSG" "$L_PRIVMSG" | sed -e 's/.*: *//')"
86f52d4
       exit 1
86f52d4
     }
86f52d4
   done
86f52d4
-- 
86f52d4
1.9.1
86f52d4
86f52d4
86f52d4
86f52d4
From fd3e8b115e160a1332773cd8e06a3305d0d680ab Mon Sep 17 00:00:00 2001
86f52d4
From: Philip Hands <phil@hands.com>
86f52d4
Date: Sat, 28 Nov 2015 21:10:39 +0100
86f52d4
Subject: [PATCH] +INFO message to mitigate the surprise described in #2196
86f52d4
86f52d4
---
86f52d4
 ssh-copy-id | 1 +
86f52d4
 1 file changed, 1 insertion(+)
86f52d4
86f52d4
diff --git $1/contrib/ssh-copy-id $1/contrib/ssh-copy-id
86f52d4
index f0b01aa..994194e 100755
86f52d4
--- $1/contrib/ssh-copy-id
86f52d4
+++ $1/contrib/ssh-copy-id
86f52d4
@@ -91,6 +91,7 @@ use_id_file() {
86f52d4
       exit 1
86f52d4
     }
86f52d4
   done
86f52d4
+  printf '%s: INFO: Source of key(s) to be installed: "%s"\n' "$0" $PUB_ID_FILE >&2
86f52d4
   GET_ID="cat \"$PUB_ID_FILE\""
86f52d4
 }
86f52d4
 
86f52d4
-- 
86f52d4
1.9.1
86f52d4
86f52d4
86f52d4
86f52d4
From 783ef08b0a757402aba67313f08f8dbfa9bf85f3 Mon Sep 17 00:00:00 2001
86f52d4
From: Philip Hands <phil@hands.com>
86f52d4
Date: Mon, 30 Nov 2015 20:46:19 +0100
86f52d4
Subject: [PATCH] deal with $HOME and id filenames that include a space
86f52d4
86f52d4
---
86f52d4
 ssh-copy-id | 15 ++++++++-------
86f52d4
 1 file changed, 8 insertions(+), 7 deletions(-)
86f52d4
86f52d4
diff --git $1/contrib/ssh-copy-id $1/contrib/ssh-copy-id
86f52d4
index 994194e..afde8b1 100755
86f52d4
--- $1/contrib/ssh-copy-id
86f52d4
+++ $1/contrib/ssh-copy-id
86f52d4
@@ -56,7 +56,7 @@ then
86f52d4
   fi
86f52d4
 fi
86f52d4
 
86f52d4
-DEFAULT_PUB_ID_FILE=$(ls -t ${HOME}/.ssh/id*.pub 2>/dev/null | grep -v -- '-cert.pub$' | head -n 1)
86f52d4
+DEFAULT_PUB_ID_FILE="$HOME/$(cd "$HOME" ; ls -t .ssh/id*.pub 2>/dev/null | grep -v -- '-cert.pub$' | head -n 1)"
86f52d4
 
86f52d4
 usage () {
86f52d4
   printf 'Usage: %s [-h|-?|-f|-n] [-i [identity_file]] [-p port] [[-o <ssh -o options>] ...] [user@]hostname\n' "$0" >&2
86f52d4
@@ -83,15 +83,15 @@ use_id_file() {
86f52d4
   [ "$FORCED" ] || PRIV_ID_FILE=$(dirname "$PUB_ID_FILE")/$(basename "$PUB_ID_FILE" .pub)
86f52d4
 
86f52d4
   # check that the files are readable
86f52d4
-  for f in $PUB_ID_FILE $PRIV_ID_FILE ; do
86f52d4
-    ErrMSG=$( { : < $f ; } 2>&1 ) || {
86f52d4
+  for f in "$PUB_ID_FILE" ${PRIV_ID_FILE:+"$PRIV_ID_FILE"} ; do
86f52d4
+    ErrMSG=$( { : < "$f" ; } 2>&1 ) || {
86f52d4
       local L_PRIVMSG=""
86f52d4
       [ "$f" = "$PRIV_ID_FILE" ] && L_PRIVMSG="	(to install the contents of '$PUB_ID_FILE' anyway, look at the -f option)"
86f52d4
       printf "\n%s: ERROR: failed to open ID file '%s': %s\n" "$0" "$f" "$(printf "%s\n%s\n" "$ErrMSG" "$L_PRIVMSG" | sed -e 's/.*: *//')"
86f52d4
       exit 1
86f52d4
     }
86f52d4
   done
86f52d4
-  printf '%s: INFO: Source of key(s) to be installed: "%s"\n' "$0" $PUB_ID_FILE >&2
86f52d4
+  printf '%s: INFO: Source of key(s) to be installed: "%s"\n' "$0" "$PUB_ID_FILE" >&2
86f52d4
   GET_ID="cat \"$PUB_ID_FILE\""
86f52d4
 }
86f52d4
 
86f52d4
@@ -217,12 +217,13 @@ populate_new_ids() {
86f52d4
     printf '%s: ERROR: mktemp failed\n' "$0" >&2
86f52d4
     exit 1
86f52d4
   fi
86f52d4
-  trap "rm -f $L_TMP_ID_FILE ${L_TMP_ID_FILE}.pub" EXIT TERM INT QUIT
86f52d4
+  local L_CLEANUP="rm -f \"$L_TMP_ID_FILE\" \"${L_TMP_ID_FILE}.stderr\""
86f52d4
+  trap "$L_CLEANUP" EXIT TERM INT QUIT
86f52d4
   printf '%s: INFO: attempting to log in with the new key(s), to filter out any that are already installed\n' "$0" >&2
86f52d4
   NEW_IDS=$(
86f52d4
     eval $GET_ID | {
86f52d4
       while read ID || [ "$ID" ] ; do
86f52d4
-        printf '%s\n' "$ID" > $L_TMP_ID_FILE
86f52d4
+        printf '%s\n' "$ID" > "$L_TMP_ID_FILE"
86f52d4
 
86f52d4
         # the next line assumes $PRIV_ID_FILE only set if using a single id file - this
86f52d4
         # assumption will break if we implement the possibility of multiple -i options.
86f52d4
@@ -246,7 +247,7 @@ populate_new_ids() {
86f52d4
       done
86f52d4
     }
86f52d4
   )
86f52d4
-  rm -f $L_TMP_ID_FILE* && trap - EXIT TERM INT QUIT
86f52d4
+  eval "$L_CLEANUP" && trap - EXIT TERM INT QUIT
86f52d4
 
86f52d4
   if expr "$NEW_IDS" : "^ERROR: " >/dev/null ; then
86f52d4
     printf '\n%s: %s\n\n' "$0" "$NEW_IDS" >&2
86f52d4
-- 
86f52d4
1.9.1
86f52d4
86f52d4
c9e7e79
diff --git a/contrib/ssh-copy-id b/contrib/ssh-copy-id
c9e7e79
index afde8b1..cd52764 100644
c9e7e79
--- a/contrib/ssh-copy-id
c9e7e79
+++ b/contrib/ssh-copy-id
c9e7e79
@@ -170,6 +170,8 @@ do
c9e7e79
       usage
c9e7e79
       ;;
c9e7e79
   esac
c9e7e79
+
c9e7e79
+  [ "x$SSH_COPY_ID_LEGACY" != "x" ] && FORCED=1
c9e7e79
 done 
c9e7e79
 
c9e7e79
 eval set -- "$SAVEARGS"
c9e7e79
diff --git a/contrib/ssh-copy-id.1 b/contrib/ssh-copy-id.1
c9e7e79
index 8850cce..62f112d 100644
c9e7e79
--- a/contrib/ssh-copy-id.1
c9e7e79
+++ b/contrib/ssh-copy-id.1
c9e7e79
@@ -185,6 +185,22 @@ should prove enlightening (N.B. the modern approach is to use the
c9e7e79
 .Fl W
c9e7e79
 option, rather than
c9e7e79
 .Xr nc 1 ) .
c9e7e79
+.Sh ENVIRONMENT
c9e7e79
+.Bl -tag -width Ds
c9e7e79
+.Pp
c9e7e79
+.It Pa SSH_COPY_ID_LEGACY
c9e7e79
+If the
c9e7e79
+.Cm SSH_COPY_ID_LEGACY
c9e7e79
+environment variable is set, the
c9e7e79
+.Nm
c9e7e79
+is run in a legacy mode. In this mode, the
c9e7e79
+.Nm
c9e7e79
+doesn't check an existence of a private key and doesn't do remote checks
c9e7e79
+of the remote server versions or if public keys are already installed
c9e7e79
+(equivalent to
c9e7e79
+.Fl f
c9e7e79
+switch).
c9e7e79
+.El
c9e7e79
 .Sh "SEE ALSO"
c9e7e79
 .Xr ssh 1 ,
c9e7e79
 .Xr ssh-agent 1 ,