简体   繁体   English

无法通过 SSH 隧道克隆 git

[英]Unable to clone git via SSH Tunnel

TLDR TLDR

I am trying to ssh tunnel in from my linux machine into a OSx machine that has access to my VPN.我正在尝试从我的 linux 机器通过 ssh 隧道进入可以访问我的 VPN 的 OSx 机器。 This is the URL that I need access github.someprivateurl.net .这是我需要访问github.someprivateurl.net的 URL。

The actual problem in details.详细的实际问题。

Setting up tunnel设置隧道

hutber@hutber ~ $ ssh -L 3333:github.someprivateurl.net:22 hutber@192.168.1.18
Password:
Last login: Thu Jun  7 01:00:34 2018 from 192.168.1.3
hutber@Jamies-Mac ~ $ 
hutber@Jamies-Mac ~/www/jamie $ git clone ssh://git@github.someprivateurl.net/Mortgages/mortgages.git
Cloning into 'mortgages-ui'...
remote: Counting objects: 63823, done.
remote: Compressing objects: 100% (52/52), done.
^Cfatal: The remote end hung up unexpectedlyMiB | 8.44 MiB/s  

^ is just to show that when ssh'd into the OSx I am able to clone within this machine. ^ 只是为了表明当 ssh 进入 OSx 时,我能够在这台机器内进行克隆。

Accessing the tunnel进入隧道

hutber@hutber /var/www $ git clone ssh://git@github.someprivateurl.net:3333/Mortgages/mortgages-ui.git


Cloning into 'mortgages-ui'... 

The above clone on my linux machine will hang until the connection realises it doesn't have access and throws me out.我的 linux 机器上的上述克隆将挂起,直到连接意识到它无权访问并将我扔出去。

I'm not sure how helpful this is... But I am unable to reach the site I am trying to clone, so its obviously nothing to do with git:我不确定这有多大帮助......但我无法访问我试图克隆的站点,所以它显然与 git 无关:

OSx操作系统

hutber@Jamies-Mac ~/www/jamie $ ping github.someprivateurl.net
PING github.someprivateurl.net (10.113.188.195): 56 data bytes
Request timeout for icmp_seq 0
Request timeout for icmp_seq 1
^Z
[1]+  Stopped                 ping github.someprivateurl.net

Linux Linux

hutber@hutber /var/www $ ping -p 3333 github.someprivateurl.net
PATTERN: 0x3333
PING github.someprivateurl.net (159.34.88.181) 56(84) bytes of data.
From 172.16.24.82 icmp_seq=1 Time to live exceeded
From 172.16.24.82 icmp_seq=2 Time to live exceeded
From 172.16.24.82 icmp_seq=3 Time to live exceeded
From 172.16.24.82 icmp_seq=4 Time to live exceeded
^C
--- github.someprivateurl.net ping statistics ---
4 packets transmitted, 0 received, +4 errors, 100% packet loss, time 3004ms

How can I clone the repo on my linux machine whilst ssh'd into OSx?如何在 ssh 进入 OSx 的同时在我的 linux 机器上克隆 repo?

Update更新

As this is I believe just a SSH error.因为这是我相信只是一个 SSH 错误。 I should mention, that the SSh is actually through Host to guest SSH.我应该提到,SSh 实际上是通过主机到访客 SSH。 My guest has a host-only connection and is connected to the internet via its own physical wifi dongle.我的客人有一个仅限主机的连接,并通过自己的物理 wifi 加密狗连接到互联网。 Its the wifi connection that the VPN is setup.它是设置 VPN 的 wifi 连接。


hutber@hutber ~ $ ssh -fNT -L 3333:github.someprivateurl.net:22 hutber@192.168.1.18
Password:
hutber@hutber /var/www $ ssh -p 3333 github.someprivateurl.net
^C //Hangs
hutber@hutber /var/www $ telnet localhost 3333
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
SSH-2.0-libssh_0.7.0
^^
Connection closed by foreign host.

$ ping -p 3333 github.someprivateurl.net

-p does not mean the port to ping. -p并不意味着要 ping 的端口。 It means... something else.这意味着……别的东西。 So that's not checking if port 3333 is open, you're just pinging the machine in a weird way.所以这不是检查端口 3333 是否打开,你只是在以一种奇怪的方式 ping 机器。

Your git ssh URL is incorrect.您的 git ssh URL 不正确。 Rather than using port 3333 on the remote host you're tunneling to, you have to tell it to use localhost's port 3333.您必须告诉它使用本地主机的端口 3333,而不是使用隧道连接到的远程主机上的端口 3333。

git clone ssh://git@localhost:3333/Mortgages/mortgages-ui.git

As with most git+ssh problems, it's easiest to debug them as ssh problems.与大多数 git+ssh 问题一样,最容易将它们作为 ssh 问题进行调试。 First is to actually try sshing to port 3333.首先是实际尝试 SSH 到端口 3333。

ssh -p 3333 localhost

I suspect that's not going to work.我怀疑这行不通。 From there, debug the ssh problem normally.从那里,正常调试 ssh 问题。

I suspect your tunnel is not actually running because your tunnel shut down as soon as you logged out of the ssh session it opened.我怀疑您的隧道实际上并未运行,因为您的隧道在您退出它打开的 ssh 会话后立即关闭。 You need some extra flags to make it persist as a tunnel.您需要一些额外的标志以使其作为隧道持续存在。 Specifically...具体来说...

  • -f to tell ssh to go to the background immediately -f告诉ssh立即进入后台
  • -N to stop it from trying to execute a remote command -N阻止它尝试执行远程命令
  • -T to not allocate a pseudo-terminal do handle typing -T不分配伪终端来处理打字

So that's...所以那是...

ssh -fNT -L 3333:github.someprivateurl.net:22 hutber@192.168.1.18

You'll also want to look into using autossh to keep the connection up for you.您还需要考虑使用autossh为您保持连接。

edit: i accidentally missed a part of the question, so this does not apply. 编辑:我不小心错过了一部分问题,所以这并不适用。

-Try replacing git protocol with https . -尝试将git协议替换为https。

-Download the zip on your local machine and scp it to your server. -将zip下载到本地计算机上,然后将其压缩到服务器上。

-Remove the tunnel. -拆除隧道。 doesnt make sense either. 也没有道理。 You could just ssh into it. 您可以只使用它。 Or setup the vpn from your current machine. 或在当前计算机上设置VPN。 That's what's vpn is for. 这就是vpn的用途。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM