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

4 messages from 2012-03-20 to 2012-03-20. Participants: Maciej Małecki, Junio C Hamano, Robin H. Johnson.
Thread: https://gitlist.dev/t/30002

## Maciej Małecki, 2012-03-20 01:39

Subject: [PATCH] Use SSH key from `GIT_SSH_KEY` variable if supplied
Message-ID: <1332207557-10965-1-git-send-email-me@mmalecki.com>
URL: https://gitlist.dev/e/1332207557-10965-1-git-send-email-me%40mmalecki.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

```

## Junio C Hamano, 2012-03-20 01:55

Subject: Re: [PATCH] Use SSH key from `GIT_SSH_KEY` variable if supplied
Message-ID: <7vhaxk829x.fsf@alter.siamese.dyndns.org>
URL: https://gitlist.dev/e/7vhaxk829x.fsf%40alter.siamese.dyndns.org
In-Reply-To: <1332207557-10965-1-git-send-email-me@mmalecki.com>

```
Maciej Małecki <me@mmalecki.com> writes:

>  	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;
> +		}

Hmm. I am somewhat torn.

The minimalist in me finds this extraneous and unnecessary noise.  Why
should the user always set GIT_SSH_KEY environment variable that only
applies to git and does not help his other ssh sessions?  Why isn't having
an entry in .ssh/config to name IdentityFile sufficient?

On the other hand, the feature-creepist in me finds this somewhat lacking.
Why should we give special treatment only to "-i $identity_file" option
[*1*] and not others?  Do we have to invent new environment variables if
we wanted to pass "-c $cipher_spec", "-l $login_name", "-I $pkcs11", "-4",
"-6", or "-b $bind_address"?

Would GIT_SSH_ARGS='-i /home/me/.ssh/there.pub -l me' be more appropriate?


[Footnote]

*1* In any case, GIT_SSH_KEY is misnamed.  It should match whatever word
ssh(1) uses to describe the concept--in this case, it is "identity file".

```

## Robin H. Johnson, 2012-03-20 02:07

Subject: Re: [PATCH] Use SSH key from `GIT_SSH_KEY` variable if supplied
Message-ID: <robbat2-20120320T020552-803311730Z@orbis-terrarum.net>
URL: https://gitlist.dev/e/robbat2-20120320T020552-803311730Z%40orbis-terrarum.net
In-Reply-To: <7vhaxk829x.fsf@alter.siamese.dyndns.org>

```
On Mon, Mar 19, 2012 at 06:55:06PM -0700,  Junio C Hamano wrote:
> Hmm. I am somewhat torn.
> 
> The minimalist in me finds this extraneous and unnecessary noise.  Why
> should the user always set GIT_SSH_KEY environment variable that only
> applies to git and does not help his other ssh sessions?  Why isn't having
> an entry in .ssh/config to name IdentityFile sufficient?
> 
> Would GIT_SSH_ARGS='-i /home/me/.ssh/there.pub -l me' be more appropriate?
I'd strongly prefer a generic args support, for making it easier to use
in deployment code.

-- 
Robin Hugh Johnson
Gentoo Linux: Developer, Trustee & Infrastructure Lead
E-Mail     : robbat2@gentoo.org
GnuPG FP   : 11ACBA4F 4778E3F6 E4EDF38E B27B944E 34884E85

```

## Maciej Małecki, 2012-03-20 08:07

Subject: Re: [PATCH] Use SSH key from `GIT_SSH_KEY` variable if supplied
Message-ID: <CAKC8-7zr8JKCzMwameXvXVhCcycNG8B-dzCcPiCxrqFzGr_b8w@mail.gmail.com>
URL: https://gitlist.dev/e/CAKC8-7zr8JKCzMwameXvXVhCcycNG8B-dzCcPiCxrqFzGr_b8w%40mail.gmail.com
In-Reply-To: <robbat2-20120320T020552-803311730Z@orbis-terrarum.net>

```
W dniu 20 marca 2012 03:07 użytkownik Robin H. Johnson
<robbat2@gentoo.org> napisał:
> On Mon, Mar 19, 2012 at 06:55:06PM -0700,  Junio C Hamano wrote:
>> Hmm. I am somewhat torn.
>>
>> The minimalist in me finds this extraneous and unnecessary noise.  Why
>> should the user always set GIT_SSH_KEY environment variable that only
>> applies to git and does not help his other ssh sessions?  Why isn't having
>> an entry in .ssh/config to name IdentityFile sufficient?
>>
>> Would GIT_SSH_ARGS='-i /home/me/.ssh/there.pub -l me' be more appropriate?
> I'd strongly prefer a generic args support, for making it easier to use
> in deployment code.
After rethinking it, I'm also +1 on GIT_SSH_ARGS. Should I submit a patch?
Sorry for noob question, but it'd go into a new e-mail thread, right?

```
