Git 使用具有非标准端口的远程存储库
我正在为远程存储库设置本地git项目。远程存储库正在非标准端口(4019)上提供服务 但它不起作用。相反,我收到以下错误消息:Git 使用具有非标准端口的远程存储库,git,Git,我正在为远程存储库设置本地git项目。远程存储库正在非标准端口(4019)上提供服务 但它不起作用。相反,我收到以下错误消息: ssh: connect to host git.host.de:4019 port 22: Connection refused fatal: The remote end hung up unexpectedly error: failed to push to 'ssh://root@git.host.de:4019/var/cache/git/project.g
ssh: connect to host git.host.de:4019 port 22: Connection refused
fatal: The remote end hung up unexpectedly
error: failed to push to 'ssh://root@git.host.de:4019/var/cache/git/project.git'
我的本地git配置是:
(端口和主机是实际端口和主机的占位符。)
我的git配置有什么问题?如果您在
.ssh/config
中放入类似的内容:
Host githost
HostName git.host.de
Port 4019
User root
然后您应该能够使用基本语法:
git push githost:/var/cache/git/project.git master
SSH在指定端口时不使用
:
语法。最简单的方法是编辑~/.ssh/config
文件并添加:
Host git.host.de
Port 4019
主机git.Host.de
4019端口
然后只指定没有端口号的
git.host.de
。这避免了您的问题,而不是直接修复它,但我建议添加一个~/.ssh/config
文件并具有类似的功能
Host git_host
HostName git.host.de
User root
Port 4019
那你就可以
url = git_host:/var/cache/git/project.git
您还可以
ssh-git\u-host
和scp-git\u-host…
一切都会解决。ssh-based-git-access-method可以在/.git/config
中使用完整的URL或类似于scp的语法来指定,具体如下所示:
URL样式:
url = ssh://[user@]host.xz[:port]/path/to/repo.git/
SCP样式:
url = [user@]host.xz:path/to/repo.git/
请注意,SCP样式不允许直接更改端口,而是依赖于~/.ssh/config
中的主机定义,例如:
Host my_git_host
HostName git.some.host.org
Port 24589
User not_a_root_user
然后,您可以使用以下工具在shell中进行测试:
ssh my_git_host
并将/.git/config
中的SCP样式URI更改为:
url = my_git_host:path/to/repo.git/
试试这个
git clone ssh://user@32.242.111.21:11111/home/git/repo.git
SSH配置可能是一种解决方法,但这让我感兴趣,因为man git push说接受的SSH url格式是SSH://[user@]host.xz[:port]/path/to/repo.git/我不确定,这可能是配置git/SSH版本问题,因为我试图推送到ssh://fake@localhost:333/假地址和get(如预期)“端口333:连接被拒绝“注意,还有需要的人。语法是
git clonessh://username@主机名:333/~/repo
以获取相对于主目录或git克隆的路径ssh://username@主机名:333/path/to/repo用于windows计算机的绝对路径:c:/windows/system32/drivers/etc/hosts,用于在需要时设置主机名(例如虚拟机/服务器)如果我有一个IP而没有主机名,怎么做?我问是因为我们还没有把我们的主机名链接到我们的ip上。。。真正需要做的就是在url前面添加一个ssh://可能。没有意识到您可以指定ssh url,或者scp(默认)不允许端口号。Good to know.scp实际上允许端口号(但选项键必须是大写字母P):scp-P 2020 file/to/copyuser@host:path/to/copy/file/to
对我来说,将ssh://
添加到我的url
就足够了。如果缺少协议,则git使用默认端口:22
。谢谢。看起来如果您没有明确地将ssh://
放在url前面,它会认为这是一种不同的格式。所以ssh://example.com:444/etc/
is/etc/on example.com通过端口44。而example.com:444/etc/
is/444/etc/通过端口22在example.com上。@Kzqai备注很重要。i、 e如果您使用git远程设置url源git@altssh.bitbucket.org:443/yourname/yourrepo/
它不起作用。但是,如果您使用git远程设置url源ssh://git@altssh.bitbucket.org:443/yourname/yourrepo/
这将适用于Google fu-当我将phabricator设置为非默认端口2222时,我遇到了这个问题。现在,分类!嗨,瑞奇,语法git克隆对我很有用ssh://user@machine:repo的端口/路径,在这里您编写的机器必须是用户,谢谢
git clone ssh://user@32.242.111.21:11111/home/git/repo.git