2

I have weird case where I'm being told my IT to use the port inside the ssh URL to connect to a git server. My original ssh config is the following:

Host my-host-alias
  HostName redacted.redacted.edu
  Port 2222
  User git
  IdentityFile ~/.ssh/my-ssh-private-key

and I was using the git remote url ssh://git@my-host-alias/path/to/repo.git. I was getting some weird Auth errors with that config (though basic functionality was still working) so IT instructed me to use the git remote url ssh://git@redacted.redacted.edu:2222/path/to/repo.git and that appeared to work with a manually specified GIT_SSH_COMMAND='ssh -i ~/.ssh/my-private-ssh-key. So I reconfigured my .ssh/config as follows:

Host redacted.redacted.edu:2222
  IdentityFile ~/.ssh/my-ssh-private-key

Suddenly, it seems as if ssh can't parse the Host entry anymore. If I run ssh -Tvvv ssh://git@redacted.redacted.edu I get the following output (snippet):

debug1: /Users/myuser/.ssh/config line 94: Applying options for *
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 48: Applying options for *
debug1: /etc/ssh/ssh_config line 52: Applying options for *

It appears that specifying a Host with a port in the URL breaks the parsing of .ssh/config. Can someone verify this?

medley56
  • 1,181
  • 1
  • 14
  • 29
  • Your first config looks good to me. I don't know what `weird Auth errors` you were getting because you didn't specify them. And you don't them to pass username manually: `git clone my-host-alias:path/to/repo.git` should be enough. – Arkadiusz Drabczyk Apr 29 '20 at 18:28
  • Yes, `host:port` is the wrong format for a `Host` line in an ssh config. – torek Apr 29 '20 at 20:48
  • @ArkadiuszDrabczyk the auth errors turned out to be unrelated to the .ssh/config issue. There isn't any issue with specifying the user explicitly, though I suspect it gets overridden by the config file if `User` is present. – medley56 Apr 29 '20 at 23:48
  • @torek could you point me to where in the openssh documentation there is such a constraint on the format? – medley56 Apr 29 '20 at 23:48
  • `I suspect it gets overridden by the config file if User` - whatever you type on the command line takes precedence. But as you already specified user in the config you don't need to do that again on the command line. – Arkadiusz Drabczyk Apr 29 '20 at 23:50
  • 1
    It's not a constraint. That is, it's not that it's *syntactically* wrong. It's that when ssh goes to look for the line, it uses only the *host name*. So if you use `ssh user@host:port command ...` or in this case `ssh://user@host:port/path/to/repo.git`, ssh only looks for `Host host`, not `Host host:port`; the string `host:port` won't match the string `host` and ssh will move on to the next configuration entry. – torek Apr 30 '20 at 07:45

1 Answers1

0

The SSH URI syntax won't use ~/.ssh/config

The SCP syntax used by OpenSSH (1999), from the history of the SSH protocol, predates URI (finalized with RFC 3986, January 2005)

So you need to use my-host-alias:path/to/repo.git if you want to use .ssh/config.

Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250