[PATCH] ssh-keyscan also emits the port used for key retrieval, if non-default

Michael Handler michael at grendel.net
Thu Apr 9 19:17:58 AEST 2015


If you invoke ssh-keyscan with a non-default port via -p, it won't log
that port data in the hostname portion of the key data it prints out.
-------------- next part --------------
diff --git a/ssh-keyscan.c b/ssh-keyscan.c
index c5fb3b5..d4fc7d7 100644
--- a/ssh-keyscan.c
+++ b/ssh-keyscan.c
@@ -305,7 +305,11 @@ keyprint(con *c, struct sshkey *key)
 	if (hash_hosts && (host = host_hash(host, NULL, 0)) == NULL)
 		fatal("host_hash failed");
 
-	fprintf(stdout, "%s ", host);
+	if (ssh_port != SSH_DEFAULT_PORT) {
+		fprintf(stdout, "%s:%d ", host, ssh_port);
+	} else {
+		fprintf(stdout, "%s ", host);
+	}
 	sshkey_write(key, stdout);
 	fputs("\n", stdout);
 }
@@ -488,7 +492,7 @@ congreet(int s)
 		confree(s);
 		return;
 	}
-	fprintf(stderr, "# %s %s\n", c->c_name, chop(buf));
+	fprintf(stderr, "# %s:%d %s\n", c->c_name, ssh_port, chop(buf));
 	n = snprintf(buf, sizeof buf, "SSH-%d.%d-OpenSSH-keyscan\r\n",
 	    c->c_keytype == KT_RSA1? PROTOCOL_MAJOR_1 : PROTOCOL_MAJOR_2,
 	    c->c_keytype == KT_RSA1? PROTOCOL_MINOR_1 : PROTOCOL_MINOR_2);


More information about the openssh-unix-dev mailing list