我知道我的ssh配置有效,因为我可以输入ssh myAlias.ssh和连接就好了.
我正在尝试使用该命令hg clone ssh://myAlias.ssh//path/to/repo并获得一个remote: ssh: Could not resolve hostname myAlias.ssh: No such file or directory
可以在这里使用SSH别名吗?
Mercurial可以使用创建的别名~/.ssh/config- 我在Linux和OS X上一直使用此功能.这是有效的,因为Mercurial不会尝试解析主机名本身,而是依靠SSH来执行此操作(并传递错误) ,当它遇到一个).这就是错误ssh:作为其前缀的一部分的原因.Bitbucket甚至可以帮助设置别名.ssh/config.(在链接的示例中,他们使用它来管理两个单独的身份.)如果您通过另一种机制创建别名,比如说BASH alias,那么这将无效,因为它依赖于Mercurial不使用的BASH.
我还浏览了Mercurial源代码clone,包括检查sshpeer.py和util.pySSH相关部分,Mercurial确实将主机名/别名传递给SSH以进行正确的解析/解释.
为文档字符串 class url中util.py的水银(2.6.3)的源代码的:
Reliable URL parser.
This parses URLs and provides attributes for the following
components:
<scheme>://<user>:<passwd>@<host>:<port>/<path>?<query>#<fragment>
Missing components are set to None. The only exception is
fragment, which is set to '' if present but empty.
If parsefragment is False, fragment is included in query. If
parsequery is False, query is included in path. If both are
False, both fragment and query are included in path.
See http://www.ietf.org/rfc/rfc2396.txt for more information.
Note that for backward compatibility reasons, bundle URLs do not
take host names. That means 'bundle://../' has a path of '../'.
Examples:
>>> url('http://www.ietf.org/rfc/rfc2396.txt')
<url scheme: 'http', host: 'www.ietf.org', path: 'rfc/rfc2396.txt'>
>>> url('ssh://[::1]:2200//home/joe/repo')
<url scheme: 'ssh', host: '[::1]', port: '2200', path: '/home/joe/repo'>
>>> url('file:///home/joe/repo')
<url scheme: 'file', path: '/home/joe/repo'>
>>> url('file:///c:/temp/foo/')
<url scheme: 'file', path: 'c:/temp/foo/'>
>>> url('bundle:foo')
<url scheme: 'bundle', path: 'foo'>
>>> url('bundle://../foo')
<url scheme: 'bundle', path: '../foo'>
>>> url(r'c:\foo\bar')
<url path: 'c:\\foo\\bar'>
>>> url(r'\\blah\blah\blah')
<url path: '\\\\blah\\blah\\blah'>
>>> url(r'\\blah\blah\blah#baz')
<url path: '\\\\blah\\blah\\blah', fragment: 'baz'>
Authentication credentials:
>>> url('ssh://joe:xyz@x/repo')
<url scheme: 'ssh', user: 'joe', passwd: 'xyz', host: 'x', path: 'repo'>
>>> url('ssh://joe@x/repo')
<url scheme: 'ssh', user: 'joe', host: 'x', path: 'repo'>
Query strings and fragments:
>>> url('http://host/a?b#c')
<url scheme: 'http', host: 'host', path: 'a', query: 'b', fragment: 'c'>
>>> url('http://host/a?b#c', parsequery=False, parsefragment=False)
<url scheme: 'http', host: 'host', path: 'a?b#c'>
Run Code Online (Sandbox Code Playgroud)
然而,该__init__方法class sshpeer中sshpeer.py(其被用于克隆经SSH)引入了密码不会在URL所允许的附加的限制:
u = util.url(path, parsequery=False, parsefragment=False)
if u.scheme != 'ssh' or not u.host or u.path is None:
self._abort(error.RepoError(_("couldn't parse location %s") % path))
self.user = u.user
if u.passwd is not None:
self._abort(error.RepoError(_("password in URL not supported")))
Run Code Online (Sandbox Code Playgroud)
(其他协议允许使用URL中的密码,但我会留下相关的代码块作为读者练习,或查看URL上的文档)
我们可以使用该-v选项查看Mercurial在克隆过程中如何与SSH交互.但首先,我的配置文件中有一些相关的摘录.
从我的.ssh/config文件:
Host bitbucket.ssh
Hostname bitbucket.org
User hg
Run Code Online (Sandbox Code Playgroud)
从我的.hgrc文件:
[ui]
# Irrelevant settings omitted
# enable compression in SSH
ssh = ssh -C
Run Code Online (Sandbox Code Playgroud)
现在,我们来看看克隆过程中会发生什么:
livius@localhost ~ $ hg clone -v ssh://bitbucket.ssh/palday/splitauthor
running ssh -C bitbucket.ssh 'hg -R palday/splitauthor serve --stdio'
destination directory: splitauthor
requesting all changes
adding changesets
adding manifests
adding file changes
added 3 changesets with 9 changes to 6 files
updating to branch default
resolving manifests
getting .hgignore
getting COPYING
getting README.rst
getting filter-revisions.awk
getting splitauthor.sh
getting testregex.sh
6 files updated, 0 files merged, 0 files removed, 0 files unresolved
Run Code Online (Sandbox Code Playgroud)
第一个输出行确实说明了一切:Mercurial将它从URL解析出的主机名 - 在这种情况下是您的别名 - 传递给SSH,它处理解析主机名/别名的实际问题.
在您的示例中hg clone ssh://myAlias.ssh//path/to/repo,主机名后面有一个斜杠太多,但我假设这只是在示例中.如果不是,这可能导致您的路径是绝对的,而不是相对于用户名(如配置中.ssh/config).另请参阅文档中的示例hg clone
我也发现确切的错误消息有点奇怪.当我使用未定义的主机名尝试此操作时,例如我未在我中定义的别名,我.ssh/config在OS X上收到以下错误:
remote: ssh: Could not resolve hostname server.ssh: nodename nor servname provided, or not known.在Linux上,我明白了remote: ssh: Could not resolve hostname server.ssh: Name or service not known.
所以,我怀疑你是在Windows上这样做的.我不知道PuTTY等在Windows上如何处理配置文件,这可能意味着语法不同,这就是你的问题所在.运行hg clone -v也可以让你看到Mercurial正在进行的确切调用,这对于追踪出错的地方也非常有用.
在Unix-y系统上,您可以尝试ssh -T myAlias.ssh测试连接和别名通过/失败,或者ssh -v myAlias.ssh在连接期间获得异常详细的输出.如果ssh -T失败,那么它肯定是一个低于Mercurial的问题.
您还可以将设置SSH本身设置为详细:您可以设置为从SSH获取详细的调试输出,而不是ssh = ssh -C像我.hgrc上面的代码段中那样ssh = ssh -Cv.这为我生成了大约70行的调试输出.