git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH] Use SSH key from `GIT_SSH_KEY` variable if supplied

From
MMMaciej Małecki <me@mmalecki.com>
Date
Mar 20, 2012, 01:39 UTC
Message-ID
<1332207557-10965-1-git-send-email-me@mmalecki.com>

Using a different SSH key for various SSH commands seems to be a recurring theme. Allow user to supply path to the SSH key he wants to use for operations that require it without need to use `GIT_SSH` variable and a wrapper script.

Signed-off-by: Maciej Małecki <me@mmalecki.com>
---
 connect.c |   10 +++++++++-
 1 files changed, 9 insertions(+), 1 deletions(-)
diff --git a/connect.c b/connect.c
index 912cdde..dd3489d 100644
--- a/connect.c
+++ b/connect.c
@@ -575,8 +575,9 @@ struct child_process *git_connect(int fd[2], const char *url_orig,
 		die("command line too long");
 
 	conn->in = conn->out = -1;
-	conn->argv = arg = xcalloc(7, sizeof(*arg));
+	conn->argv = arg = xcalloc(9, sizeof(*arg));
 	if (protocol == PROTO_SSH) {
+		const char *key;
 		const char *ssh = getenv("GIT_SSH");
 		int putty = ssh && strcasestr(ssh, "plink");
 		if (!ssh) ssh = "ssh";
@@ -589,6 +590,13 @@ struct child_process *git_connect(int fd[2], const char *url_orig,
 			*arg++ = putty ? "-P" : "-p";
 			*arg++ = port;
 		}
+
+		key = getenv("GIT_SSH_KEY");
+		if (key) {
+			*arg++ = "-i";
+			*arg++ = key;
+		}
+
 		*arg++ = host;
 	}
 	else {
-- 
1.7.7.4
Next: Junio C Hamano
Message 1 of 4 in “Use SSH key from `GIT_SSH_KEY` variable if supplied”
  1. Use SSH key from `GIT_SSH_KEY` variable if suppliedMaciej Małecki, Mar 20, 2012
  2. Junio C HamanoMar 20, 2012
  3. Robin H. JohnsonMar 20, 2012
  4. Maciej MałeckiMar 20, 2012

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.