# Re: how to pass ssh options to git?

8 messages from 2006-11-02 to 2006-11-02. Participants: Michael S. Tsirkin, Dennis Stosberg, Shawn Pearce, Linus Torvalds, Matthieu Moy, Nicolas Vilz 'niv'.
Thread: https://gitlist.dev/t/43078

## Michael S. Tsirkin, 2006-11-02 09:07

Subject: how to pass ssh options to git?
Message-ID: <20061102090717.GE7468@mellanox.co.il>
URL: https://gitlist.dev/e/20061102090717.GE7468%40mellanox.co.il

```
How is it possible to pass ssh options to git?
for example, I use these options to log into some machine:
ssh -i <private> -o HostKeyAlias=<alias> -p <port> -l <user> <address>

However, git will only let me specify the user name on command line as part of
the URL.  I am guessing something can be done using core.gitProxy?



-- 

```

## Matthieu Moy, 2006-11-02 09:20

Subject: Re: how to pass ssh options to git?
Message-ID: <vpqejsm433c.fsf@ecrins.imag.fr>
URL: https://gitlist.dev/e/vpqejsm433c.fsf%40ecrins.imag.fr
In-Reply-To: <20061102090717.GE7468@mellanox.co.il>

```
"Michael S. Tsirkin" <mst@mellanox.co.il> writes:

> How is it possible to pass ssh options to git?
> for example, I use these options to log into some machine:
> ssh -i <private> -o HostKeyAlias=<alias> -p <port> -l <user> <address>

Not answering the question, but this can go to ~/.ssh/config :

Host *.domain.net
User some_user
IdentityFile ~/.ssh/foobar

Host another.host
...

-- 

```

## Michael S. Tsirkin, 2006-11-02 09:31

Subject: Re: how to pass ssh options to git?
Message-ID: <20061102093153.GF7468@mellanox.co.il>
URL: https://gitlist.dev/e/20061102093153.GF7468%40mellanox.co.il
In-Reply-To: <vpqejsm433c.fsf@ecrins.imag.fr>

```
Quoting r. Matthieu Moy <Matthieu.Moy@imag.fr>:
> Subject: Re: how to pass ssh options to git?
> 
> "Michael S. Tsirkin" <mst@mellanox.co.il> writes:
> 
> > How is it possible to pass ssh options to git?
> > for example, I use these options to log into some machine:
> > ssh -i <private> -o HostKeyAlias=<alias> -p <port> -l <user> <address>
> 
> Not answering the question, but this can go to ~/.ssh/config :
> 
> Host *.domain.net
> User some_user
> IdentityFile ~/.ssh/foobar
> 

I know, problem is I want to use different options at different times.
I could use -F configfile ssh option, but how to pass *that* to git?

-- 

```

## Dennis Stosberg, 2006-11-02 11:06

Subject: Re: how to pass ssh options to git?
Message-ID: <20061102110639.G523a966f@leonov.stosberg.net>
URL: https://gitlist.dev/e/20061102110639.G523a966f%40leonov.stosberg.net
In-Reply-To: <20061102093153.GF7468@mellanox.co.il>

```
Michael S. Tsirkin wrote:

> I know, problem is I want to use different options at different times.
> I could use -F configfile ssh option, but how to pass *that* to git?
 
You can set the path of the ssh executable to use with the GIT_SSH
environment variable.  Create a shell script like

#!/bin/sh
exec ssh --your-options-- $*

and make GIT_SSH point to it.

Regards,

```

## Nicolas Vilz 'niv', 2006-11-02 11:18

Subject: Re: how to pass ssh options to git?
Message-ID: <4549D418.3050606@iaglans.de>
URL: https://gitlist.dev/e/4549D418.3050606%40iaglans.de
In-Reply-To: <20061102093153.GF7468@mellanox.co.il>

```
Michael S. Tsirkin wrote:
> Quoting r. Matthieu Moy <Matthieu.Moy@imag.fr>:
>> Subject: Re: how to pass ssh options to git?
>>
>> "Michael S. Tsirkin" <mst@mellanox.co.il> writes:
>>
>>> How is it possible to pass ssh options to git?
>>> for example, I use these options to log into some machine:
>>> ssh -i <private> -o HostKeyAlias=<alias> -p <port> -l <user> <address>
>> Not answering the question, but this can go to ~/.ssh/config :
>>
>> Host *.domain.net
>> User some_user
>> IdentityFile ~/.ssh/foobar
>>
> 
> I know, problem is I want to use different options at different times.
> I could use -F configfile ssh option, but how to pass *that* to git?

you can setup different host-entries as kind of virtual hosts in your 
hosts-section. that is what i do

host blah1.domain.net
hostname www.domain.net
user blah1
IdentityFile .ssh/blah
Port 523434

host blah2.domain.net
hostname www.domain.net
user blah1
IdentityFile .ssh/blah
Port 22

The first host-section i use in an environment, where i cannot get 
through port 22.


Sincerly

```

## Michael S. Tsirkin, 2006-11-02 11:27

Subject: Re: how to pass ssh options to git?
Message-ID: <20061102112720.GA8469@mellanox.co.il>
URL: https://gitlist.dev/e/20061102112720.GA8469%40mellanox.co.il
In-Reply-To: <20061102110639.G523a966f@leonov.stosberg.net>

```
Quoting r. Dennis Stosberg <dennis@stosberg.net>:
> Subject: Re: how to pass ssh options to git?
> 
> Michael S. Tsirkin wrote:
> 
> > I know, problem is I want to use different options at different times.
> > I could use -F configfile ssh option, but how to pass *that* to git?
>  
> You can set the path of the ssh executable to use with the GIT_SSH
> environment variable.  Create a shell script like
> 
> #!/bin/sh
> exec ssh --your-options-- $*
> 
> and make GIT_SSH point to it.

Thanks, I'll try that.
BTW, just grep for GIT_SSH gets me some more:
GIT_SSH_UPLOAD, GIT_SSH_PUSH, GIT_SSH_PULL, GIT_SSH_FETCH.
None of which appear to be documented.





-- 

```

## Linus Torvalds, 2006-11-02 16:10

Subject: Re: how to pass ssh options to git?
Message-ID: <Pine.LNX.4.64.0611020801160.25218@g5.osdl.org>
URL: https://gitlist.dev/e/Pine.LNX.4.64.0611020801160.25218%40g5.osdl.org
In-Reply-To: <20061102112720.GA8469@mellanox.co.il>

```


On Thu, 2 Nov 2006, Michael S. Tsirkin wrote:

> Quoting r. Dennis Stosberg <dennis@stosberg.net>:
> > Subject: Re: how to pass ssh options to git?
> > 
> > Michael S. Tsirkin wrote:
> > 
> > > I know, problem is I want to use different options at different times.
> > > I could use -F configfile ssh option, but how to pass *that* to git?
> >  
> > You can set the path of the ssh executable to use with the GIT_SSH
> > environment variable.  Create a shell script like
> > 
> > #!/bin/sh
> > exec ssh --your-options-- $*
> > 
> > and make GIT_SSH point to it.
> 
> Thanks, I'll try that.

It's really better to use a ".ssh/config" file instead.

I realize that you want to use different options "dynamically", but what 
you can do is to just have different "fake hostnames". For example, you 
can do

	Host private.host.com
		User myname
		Hostname host.com
		IdentityFile /home/myname/.ssh/private-identity
	Host public.host.com
		User groupname
		Hostname host.com
		IdentityFile /home/myname/.ssh/public-identity

and now you can ssh to "host.com" using different identities by just using 
"private.host.com" and "public.host.com" respectively. You can do pretty 
much any options that way.

Very convenient, if you have just a couple of "standard" setups.

Obviously we _could_ just add support for arbitrary ssh options, but it 
gets pretty ugly pretty quickly, so I'd suggest trying to use the 
.ssh/config approach with different hostnames if that is at all possible.


```

## Shawn Pearce, 2006-11-02 20:22

Subject: Re: how to pass ssh options to git?
Message-ID: <20061102202230.GA21456@spearce.org>
URL: https://gitlist.dev/e/20061102202230.GA21456%40spearce.org
In-Reply-To: <Pine.LNX.4.64.0611020801160.25218@g5.osdl.org>

```
Linus Torvalds <torvalds@osdl.org> wrote:
> It's really better to use a ".ssh/config" file instead.
> 
> I realize that you want to use different options "dynamically", but what 
> you can do is to just have different "fake hostnames". For example, you 
> can do
> 
> 	Host private.host.com
> 		User myname
> 		Hostname host.com
> 		IdentityFile /home/myname/.ssh/private-identity
> 	Host public.host.com
> 		User groupname
> 		Hostname host.com
> 		IdentityFile /home/myname/.ssh/public-identity

I often setup not only multiple fake hostnames in my .ssh/config
but I also setup multiple remote files under any given repository's
.git/remotes directory, using one file per fake hostname.

That way I can pick which options to apply at the time of git push
or git fetch by just changing the name passed to it.

	$ ls .git/remotes
	private public

	$ cat .git/remotes/private
	URL: private.host.com:/path/to/repo
	Pull: refs/heads/master:refs/heads/origin

	$ cat .git/remotes/public
	URL: public.host.com:/path/to/repo
	Pull: refs/heads/master:refs/heads/origin

	$ git push private
	$ git fetch public

I often need this to traverse around firewalls and whatnot.
It works pretty well, assuming I can remember where I'm currently
connected to.  :-)

-- 

```
