ssh-copy-id usability improvement

Amir Yalon yxejamir at gmail.com
Wed Nov 7 21:52:07 EST 2012


Hi,

I had trouble recently with using the ssh-copy-id -i switch (in
portable OpenSSH’s contrib/), where it told me that “no identities
found”, while I the file existed and contained a valid public key text
line. The problem was, that the file was named something.key in stead
of something.pub, and the script tried to read the non-existent
something.key.pub.

The two small patches below fix that, by checking that
something.key.pub exists before adding the .pub suffix to
something.key. Feedback is welcome, of course.

Regards,
Amir

commit 2b739db206d2bce48e3a52dd269c2a2bb641e55d
Author: Amir Yalon <git at please.nospammail.net>
Date:   Wed Nov 7 12:26:23 2012 +0200

    ssh-copy-id: enable suffix other than .pub in argument to -i

diff --git a/contrib/ssh-copy-id b/contrib/ssh-copy-id
index 9451ace..15a1646 100644
--- a/contrib/ssh-copy-id
+++ b/contrib/ssh-copy-id
@@ -11,10 +11,10 @@ if [ "-i" = "$1" ]; then
   shift
   # check if we have 2 parameters left, if so the first is the new ID file
   if [ -n "$2" ]; then
-    if expr "$1" : ".*\.pub" > /dev/null ; then
-      ID_FILE="$1"
-    else
+    if [ -f "$1.pub" ]; then
       ID_FILE="$1.pub"
+    else
+      ID_FILE="$1"
     fi
     shift         # and this should leave $1 as the target name
   fi

And also a patch for the proposed new ssh-copy-id script at
http://git.hands.com/ssh-copy-id:

commit ff8993ba2cefbb28b4648d643a73f01fec64617c
Author: Amir Yalon <git at please.nospammail.net>
Date:   Wed Nov 7 12:44:40 2012 +0200

    Enable suffix other than .pub in argument to -i

diff --git a/ssh-copy-id b/ssh-copy-id
index 8cdad28..efa0d29 100755
--- a/ssh-copy-id
+++ b/ssh-copy-id
@@ -23,10 +23,10 @@ usage () {
 use_id_file() {
   local L_ID_FILE=$1

-  if expr "$L_ID_FILE" : ".*\.pub$" >/dev/null ; then
-    PUB_ID_FILE="$L_ID_FILE"
-  else
+  if [ -f "$L_ID_FILE.pub" ]; then
     PUB_ID_FILE="$L_ID_FILE.pub"
+  else
+    PUB_ID_FILE="$L_ID_FILE"
   fi

   PRIV_ID_FILE=$(dirname "$PUB_ID_FILE")/$(basename "$PUB_ID_FILE" .pub)


More information about the openssh-unix-dev mailing list