linux - 无法通过 SSH 隧道克隆 git

标签 linux git macos ssh ssh-tunnel

TLDR

我正在尝试从我的 Linux 计算机通过 ssh 隧道连接到可以访问我的 VPN 的 OSx 计算机。这是我需要访问 github.someprivateurl.net 的 URL。

实际问题的详细信息。

设置隧道

hutber@hutber ~ $ ssh -L 3333:github.someprivateurl.net:22 <a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="78100d0c1a1d0a3849414a56494e405649564940" rel="noreferrer noopener nofollow">[email protected]</a>
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://<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="65020c1125020c110d10074b160a080015170c130411001017094b0b0011" rel="noreferrer noopener nofollow">[email protected]</a>/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  

^ 只是为了表明当 ssh 进入 OSx 时我能够在这台机器中克隆。

进入隧道

hutber@hutber /var/www $ git clone ssh://<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="5e39372a1e39372a362b3c702d31333b2e2c37283f2a3b2b2c3270303b2a" rel="noreferrer noopener nofollow">[email protected]</a>:3333/Mortgages/mortgages-ui.git


Cloning into 'mortgages-ui'... 

我的 Linux 机器上的上述克隆将挂起,直到连接意识到它没有访问权限并将我抛出。

我不确定这有多大帮助...但我无法访问我尝试克隆的网站,所以它显然与 git 无关:

操作系统

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

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

如何在 ssh 进入 OSx 的同时在我的 Linux 机器上克隆存储库?

更新

因为我认为这只是一个 SSH 错误。我应该提到,SSH 实际上是通过主机到 guest SSH。我的客人有一个仅限主机的连接,并通过其自己的物理 WiFi 适配器连接到互联网。 VPN 设置的 WiFi 连接。


hutber@hutber ~ $ ssh -fNT -L 3333:github.someprivateurl.net:22 <a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="b3dbc6c7d1d6c1f3828a819d82858b9d829d828b" rel="noreferrer noopener nofollow">[email protected]</a>
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 并不表示要 ping 的端口。这意味着……别的东西。所以这并不是检查端口 3333 是否打开,您只是以一种奇怪的方式 ping 机器。

您的 git ssh URL 不正确。您必须告诉它使用本地主机的端口 3333,而不是使用要通过隧道连接到的远程主机上的端口 3333。

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

与大多数 git+ssh 问题一样,将它们作为 ssh 问题进行调试是最简单的。首先是实际尝试 sshing 到端口 3333。

ssh -p 3333 localhost

我怀疑这行不通。从那里,正常调试 ssh 问题。

我怀疑您的隧道实际上并未运行,因为一旦您注销它打开的 ssh session ,您的隧道就会关闭。您需要一些额外的标志才能使其作为隧道持续存在。具体来说...

  • -f 告诉ssh立即转到后台
  • -N 阻止它尝试执行远程命令
  • -T 不分配伪终端来处理输入

所以这是...

ssh -fNT -L 3333:github.someprivateurl.net:22 <a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="c3abb6b7a1a6b183f2faf1edf2f5fbedf2edf2fb" rel="noreferrer noopener nofollow">[email protected]</a>

您还需要考虑使用 autossh为您保持连接。

关于linux - 无法通过 SSH 隧道克隆 git,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50731396/

相关文章:

regex - linux/unix 中的模式匹配或 RegEx 手册页?

c# - 提交到 Git 对象数据库有什么好处?

macos - 无法在 Mac 上测试 Mosquitto 服务器

macos - ndk-gdb 失败并显示消息 : Invalid attribute name: package

linux - 模式匹配在 bash 脚本中不起作用

python - 制作python终端用户界面

python-3.x - 识别 git 提交的实际分支名称

git - 是否可以在 git 中查看 Remote 的 Remote ?

macos - App B 关闭时关闭 App A : Mac OS X 10. 7.3

linux - Kali Linux Metasploit 框架奇怪的行为