[PATCH]: ssh-add and multiple keys

Eduardo Santiago esm at pobox.com
Thu Apr 5 22:36:00 EST 2001


Greetings,

The enclosed patch to ssh-add.c (from OpenSSH 2.5.2p2) changes the 
behavior of ssh-add when called with no arguments.  Instead of 
defaulting to ~/.ssh/identity, it checks for the existence of, and 
processes if it exists, each of the following (from pathnames.h):

  _PATH_SSH_CLIENT_IDENTITY      ~/.ssh/identity
  _PATH_SSH_CLIENT_ID_DSA        ~/.ssh/id_dsa
  _PATH_SSH_CLIENT_ID_RSA        ~/.ssh/id_rsa

I understand the arguments against this sort of thing; I even
agree that the clueful user should explicitly specify the keys.

However, the defaults are already there.  ssh-keygen and ssh
default to these, and it is confusing that ssh-add does not.

Thanks to all for your efforts; OpenSSH is a terrific product.

^E
-- 
Ed Santiago                 Toolsmith                 esm at pobox.com


-------------- next part --------------
--- ssh-add.c.ORIG	Tue Apr  3 12:51:55 2001
+++ ssh-add.c	Tue Apr  3 18:32:45 2001
@@ -287,6 +287,11 @@
 			add_file(ac, argv[i]);
 	}
 	if (no_files) {
+		char *ident_files[] = { _PATH_SSH_CLIENT_IDENTITY,
+					_PATH_SSH_CLIENT_ID_DSA,
+					_PATH_SSH_CLIENT_ID_RSA };
+		struct stat st;
+
 		pw = getpwuid(getuid());
 		if (!pw) {
 			fprintf(stderr, "No user found with uid %u\n",
@@ -294,11 +299,17 @@
 			ssh_close_authentication_connection(ac);
 			exit(1);
 		}
-		snprintf(buf, sizeof buf, "%s/%s", pw->pw_dir, _PATH_SSH_CLIENT_IDENTITY);
-		if (deleting)
-			delete_file(ac, buf);
-		else
-			add_file(ac, buf);
+
+		/* Default (no args): try to load all "standard" ID files */
+		for (i=0; i < sizeof(ident_files) / sizeof(ident_files[0]); i++) {
+			snprintf(buf, sizeof buf, "%s/%s", pw->pw_dir, ident_files[i]);
+			if (stat(buf, &st) == 0) {
+				if (deleting)
+					delete_file(ac, buf);
+				else
+					add_file(ac, buf);
+			}
+		}
 	}
 	ssh_close_authentication_connection(ac);
 	exit(0);


More information about the openssh-unix-dev mailing list