# How can I specify a non-standard TCP port for a git+ssh connection?

2 messages from 2005-12-02 to 2005-12-02. Participants: Andreas Jochens, Linus Torvalds.
Thread: https://gitlist.dev/t/2730

## Andreas Jochens, 2005-12-02 12:48

Subject: How can I specify a non-standard TCP port for a git+ssh connection?
Message-ID: <20051202124801.GA20332@andaco.de>
URL: https://gitlist.dev/e/20051202124801.GA20332%40andaco.de

```
Hello,

is there a simple way to specify a non-standard TCP port for a git+ssh
connection? 

The following small patch would allow to use an URL like 
'git+ssh://user@hostname:port/path' to specify an arbitrary 
port for the ssh connection.

Regards
Andreas Jochens

 connect.c |   12 ++++++++++--
 1 files changed, 10 insertions(+), 2 deletions(-)

diff --git a/connect.c b/connect.c
index 93f6f80..4b640dd 100644
--- a/connect.c
+++ b/connect.c
@@ -560,7 +560,7 @@ static int git_proxy_connect(int fd[2], 
 int git_connect(int fd[2], char *url, const char *prog)
 {
 	char command[1024];
-	char *host, *path = url;
+	char *host, *port = NULL, *path = url;
 	char *colon = NULL;
 	int pipefd[2][2];
 	pid_t pid;
@@ -597,6 +597,10 @@ int git_connect(int fd[2], char *url, co
 			path = strdup(ptr);
 
 		*ptr = '\0';
+		if ((colon = strchr(host, ':'))) {
+			*colon = '\0';
+			port = colon + 1;
+		}
 	}
 
 	if (protocol == PROTO_GIT) {
@@ -626,7 +630,11 @@ int git_connect(int fd[2], char *url, co
 				ssh_basename = ssh;
 			else
 				ssh_basename++;
-			execlp(ssh, ssh_basename, host, command, NULL);
+			if (port)
+				execlp(ssh, ssh_basename, "-p", port, host, 
+				       command, NULL);
+			else
+				execlp(ssh, ssh_basename, host, command, NULL);
 		}
 		else
 			execlp("sh", "sh", "-c", command, NULL);

```

## Linus Torvalds, 2005-12-02 16:07

Subject: Re: How can I specify a non-standard TCP port for a git+ssh connection?
Message-ID: <Pine.LNX.4.64.0512020805480.3099@g5.osdl.org>
URL: https://gitlist.dev/e/Pine.LNX.4.64.0512020805480.3099%40g5.osdl.org
In-Reply-To: <20051202124801.GA20332@andaco.de>

```


On Fri, 2 Dec 2005, Andreas Jochens wrote:
> 
> is there a simple way to specify a non-standard TCP port for a git+ssh
> connection? 

Use the ".ssh/config" file ;)

> The following small patch would allow to use an URL like 
> 'git+ssh://user@hostname:port/path' to specify an arbitrary 
> port for the ssh connection.

Maybe. On the other hand, I think we'd be better off  with perhaps some 
way to just specify arbitrary options to the "ssh" program. Sometimes you 
might want to specify identity-files etc too.

		Linus

```
