threads / discuss / 43078

Re: how to pass ssh options to git?

Subject: Re: how to pass ssh options to git?

## tl;dr

8 messages between Nov 2, 2006 and Nov 2, 2006.

replies: 7people: 6as markdown or json

Michael S. Tsirkin· Nov 2, 2006, 09:07 UTC · lore

how to pass ssh options to git?

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· Nov 2, 2006, 09:20 UTC · re: Michael S. Tsirkin · lore
"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· Nov 2, 2006, 09:31 UTC · re: Matthieu Moy · lore
Quoting r. Matthieu Moy <Matthieu.Moy@imag.fr>:
Show 14 quoted lines
> 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· Nov 2, 2006, 11:06 UTC · re: Michael S. Tsirkin · lore
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,
Michael S. Tsirkin· Nov 2, 2006, 11:27 UTC · re: Dennis Stosberg · lore
Quoting r. Dennis Stosberg <dennis@stosberg.net>:
Show 14 quoted lines
> 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· Nov 2, 2006, 16:10 UTC · re: Michael S. Tsirkin · lore
On Thu, 2 Nov 2006, Michael S. Tsirkin wrote:
Show 17 quoted lines
> 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· Nov 2, 2006, 20:22 UTC · re: Linus Torvalds · lore
Linus Torvalds <torvalds@osdl.org> wrote:
Show 14 quoted lines
> 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. :-)

Nicolas Vilz 'niv'· Nov 2, 2006, 11:18 UTC · re: Michael S. Tsirkin · lore
Michael S. Tsirkin wrote:
Show 17 quoted lines
> 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

← back to recent threads