# [PATCH] GIT_SSH alternate ssh name or helper

4 messages from 2005-08-03 to 2005-08-03. Participants: Martin Sivak, Junio C Hamano.
Thread: https://gitlist.dev/t/1407

## Martin Sivak, 2005-08-03 15:15

Subject: [PATCH] GIT_SSH alternate ssh name or helper
Message-ID: <20050803151542.GA6655@medusa>
URL: https://gitlist.dev/e/20050803151542.GA6655%40medusa

```
This patch make possible to use alternate ssh binary or ssh helper
script. The script can be used to give additional parameters to ssh
binary (like private key, protocol version, ...).

Example script could look like this:

#!/bin/sh
ssh -1 -i myprivatekey.key "$@"

The patch itself is realy very simple:

diff -uNr git-current/connect.c git-current-mars@nomi.cz/connect.c
--- git-current/connect.c  2005-08-03 15:00:04.000000000 +0200
+++ git-current-mars@nomi.cz/connect.c 2005-08-03 16:32:36.000000000 +0200
@@ -166,6 +166,9 @@
   int pipefd[2][2];
   pid_t pid;
   enum protocol protocol;
+  char *sshprog;
+
+  sshprog = getenv("GIT_SSH") ? : "ssh";

   host = NULL;
   path = url;
@@ -205,7 +208,7 @@
      close(pipefd[1][0]);
      close(pipefd[1][1]);
      if (protocol == PROTO_SSH)
-        execlp("ssh", "ssh", host, command, NULL);
+        execlp(sshprog, "ssh", host, command, NULL);
      else
         execlp("sh", "sh", "-c", command, NULL);
      die("exec failed");
diff -uNr git-current/rsh.c git-current-mars@nomi.cz/rsh.c
--- git-current/rsh.c   2005-08-03 15:00:04.000000000 +0200
+++ git-current-mars@nomi.cz/rsh.c  2005-08-03 16:26:39.000000000 +0200
@@ -17,6 +17,7 @@
   char command[COMMAND_SIZE];
   char *posn;
   int i;
+  char *prog; 

   if (!strcmp(url, "-")) {
      *fd_in = 0;
@@ -24,6 +25,8 @@
      return 0;
   }

+  prog = getenv("GIT_SSH") ? : "ssh";
+  
   host = strstr(url, "//");
   if (host) {
      host += 2;
@@ -59,7 +62,7 @@
      close(sv[1]);
      dup2(sv[0], 0);
      dup2(sv[0], 1);
-     execlp("ssh", "ssh", host, command, NULL);
+     execlp(prog, "ssh", host, command, NULL);
   }
   close(sv[0]);
   *fd_in = sv[1];


Signed-off-by: Martin Sivak <mars@nomi.cz>

-- 
Martin Sivak
mars@nomi.cz


```

## Junio C Hamano, 2005-08-03 17:12

Subject: Re: [PATCH] GIT_SSH alternate ssh name or helper
Message-ID: <7viryndjvu.fsf@assigned-by-dhcp.cox.net>
URL: https://gitlist.dev/e/7viryndjvu.fsf%40assigned-by-dhcp.cox.net
In-Reply-To: <20050803151542.GA6655@medusa>

```
Martin Sivak <mars@nomi.cz> writes:

> This patch make possible to use alternate ssh binary or ssh helper
> script. The script can be used to give additional parameters to ssh
> binary (like private key, protocol version, ...).
>
> Example script could look like this:
>
> #!/bin/sh
> ssh -1 -i myprivatekey.key "$@"
>
> The patch itself is realy very simple:

I understand why you would want this if your ssh binary is
called something other than ssh [*1*], but I doubt the example
you gave needs this patch.  Could you explain why having
something like this in your .ssh/config file is not enough?

    Host foo.bar.xz
      Protocol 1
      IdentityFile ~/.ssh/privatekey.key

Even if you wish to use different settings between git and
interactive, I presume you could do something like this:

    # for interactive
    Host foo.bar.xz
      Protocol 2

    # real repo is foo.bar.xz:/pub/scm/git/git.git/ but pull with
    # git-foo.bar.xz:/pub/scm/git/git.git/
    Host git-foo.bar.xz
      Hostname foo.bar.xz
      Protocol 1
      IdentityFile ~/.ssh/privatekey.key


[Footnote]
*1* and even in that case you can trivially fix it by having
a small wrapper in $HOME/bin/ssh:

    #!/bin/sh
    exec ssh-installed-under-nonstandard-name "$@"

```

## Martin Sivak, 2005-08-03 18:56

Subject: Re: [PATCH] GIT_SSH alternate ssh name or helper
Message-ID: <20050803185621.GA20645@medusa>
URL: https://gitlist.dev/e/20050803185621.GA20645%40medusa
In-Reply-To: <7viryndjvu.fsf@assigned-by-dhcp.cox.net>

```
> I understand why you would want this if your ssh binary is
> called something other than ssh [*1*], but I doubt the example
> you gave needs this patch.  Could you explain why having
> something like this in your .ssh/config file is not enough?
> 
>     Host foo.bar.xz
>       Protocol 1
>       IdentityFile ~/.ssh/privatekey.key

The example was of course about the simpliest thing i thought of.

I would find that variable (GIT_SSH) usefull, and actually it does no
harm, because you already have GIT_SSH_PULL & PUSH variables, for the
same purpose (to define different name).

Actually I think there is at least one case, when helper script is useful.
I mean, how would you setup different identities for more user accounts on the
same server (it doesn't happen often, but..)?

Best regards
--
Martin Sivak
mars@nomi.cz


```

## Junio C Hamano, 2005-08-03 19:29

Subject: Re: [PATCH] GIT_SSH alternate ssh name or helper
Message-ID: <7v4qa6akek.fsf@assigned-by-dhcp.cox.net>
URL: https://gitlist.dev/e/7v4qa6akek.fsf%40assigned-by-dhcp.cox.net
In-Reply-To: <20050803185621.GA20645@medusa>

```
Martin Sivak <mars@nomi.cz> writes:

> I mean, how would you setup different identities for more user
> accounts on the same server (it doesn't happen often, but..)?

I do not claim the way I do is the best way, but I do that all
the time.

I just use different "name" to connect, by setting up the ssh
client configuration file to give me the protocol parameters I
want depending on the name I use.  The wildcard support handles
permutations quite nicely.  Something like this:

    $ cat .ssh/config
    Host *-1-*
      Protocol 1
    Host *-2-*
      Protocol 2
    Host lucia-*
      Hostname lucia.example.xz
    Host myriam-*
      Hostname myriam.example.xz
    Host *-junio
      IdentityFile ~/.ssh/identity-junio
      IdentityFile ~/.ssh/id_dsa-junio
    Host *-junkio
      IdentityFile ~/.ssh/identity-junkio
      IdentityFile ~/.ssh/id_dsa-junkio

    $ ssh lucia-2-junio ;# go to lucia over protocol 2, use id_dsa-junio
    $ ssh myriam-1-junkio ;# to myriam over protocol 1, use identity-junkio

```
