【问题标题】:Forward ssh protocol via ssh tunnel | corporate firewall通过 ssh 隧道转发 ssh 协议 |企业防火墙
【发布时间】:2013-05-31 09:16:57
【问题描述】:

简短

既然防火墙后面的ssh 正在运行(尤其是ssh git@bitbucket.org),为什么git pull/push 无法运行。


有人提出了类似的问题,我已经阅读了它们。 但我仍然缺乏理解。

我坐在公司防火墙后面,通过配置~/.ssh/config(使用开瓶器 +公司 http 代理)。

由于端口 22 被阻止,我想我可以设置一个 ssh 隧道,这使我能够使用端口 22 来从我的工作机执行进一步的 ssh 命令,特别是与 git push/pull 一起使用(使用不支持的 bitbucket通过 443 端口 ssh 访问...)

我很乐意提供一些意见。或者甚至是其他方法。

我只是注意到...git 使用它自己的 ssh 命令(在$GIT_SSH 中),我没有考虑过。但这只是问题的一小部分,因为即使 ssh git@bitbucket.org 也不起作用。

场景

workmachine --> 防火墙 --> asus_rtn16 --> git repo

编辑

现在转发正在运行,我可以 ssh 进入每台机器。 Git 仍然有一些问题。

~/.ssh/config

Host asus
        HostName myrouter.com
        User admin
        Port 443
        ProxyCommand C:/cygwin/bin/corkscrew.exe companyproxy proxy_port %h %p
        IdentityFile C:/cygwin/home/*user*/.ssh/id_rsa
Host *
        ProxyCommand ssh asus nc -w1 %h %p
        IdentityFile C:/cygwin/home/*user*/.ssh/id_rsa

没有提示我登录。我添加了 RSA 身份验证,但也没有提示我输入保护密钥的密码。

我确实设置了GIT_SSH指向正确的ssh,并且配置中的路径是绝对的。

当我尝试推送时会发生这种情况

$ git push --verbose -u origin --all
Pushing to ssh://git@bitbucket.org/*username*/myrepo.git
OpenSSH_4.6p1, OpenSSL 0.9.8e 23 Feb 2007
debug1: Reading configuration data /c/cygwin/home/*user*/.ssh/config
debug1: Applying options for asus
debug1: Applying options for *
debug1: Executing proxy command: exec C:/cygwin/bin/corkscrew.exe *proxy* *port* *router* 443
debug1: permanently_drop_suid: 500
debug1: identity file /c/cygwin/home/<user>/.ssh/id_rsa type 1
debug1: identity file /c/cygwin/home/<user>/.ssh/id_rsa type 1
debug1: Remote protocol version 2.0, remote software version dropbear_0.52
debug1: no match: dropbear_0.52
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_4.6
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: server->client aes128-cbc hmac-md5 none
debug1: kex: client->server aes128-cbc hmac-md5 none
debug1: sending SSH2_MSG_KEXDH_INIT
debug1: expecting SSH2_MSG_KEXDH_REPLY
debug1: Host '[*router*]:443' is known and matches the RSA host key.
debug1: Found key in /c/cygwin/home/*user*/.ssh/known_hosts:2
debug1: ssh_rsa_verify: signature correct
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug1: SSH2_MSG_NEWKEYS received
debug1: SSH2_MSG_SERVICE_REQUEST sent
debug1: SSH2_MSG_SERVICE_ACCEPT received
DD-WRT v24-sp2 big (c) 2011 NewMedia-NET GmbH
Release: 02/17/11 (SVN revision: 16214)
debug1: Authentications that can continue: publickey,password
debug1: Next authentication method: publickey
debug1: Offering public key: /c/cygwin/home/*user*/.ssh/id_rsa
debug1: Server accepts key: pkalg ssh-rsa blen 279
debug1: PEM_read_PrivateKey failed
debug1: read PEM private key done: type <unknown>    # freezes here...

fatal: Could not read from remote repository.        # continues after ctrl + c

Please make sure you have the correct access rights
and the repository exists.

正常的 ssh 连接应该像这样继续

Enter passphrase for key '/home/*user*/.ssh/id_rsa': 
debug1: read PEM private key done: type RSA
debug1: Authentication succeeded (publickey).
Authenticated to *router* (via proxy).
debug1: channel 0: new [client-session]
debug1: Entering interactive session.
debug1: Sending command: nc -w1 sdf-eu.org 22

调试 LV3

git push -u origin --all失败

debug1: Next authentication method: publickey
debug1: Offering public key: C:/cygwin/home/*user*/.ssh/id_rsa
debug3: send_pubkey_test
debug2: we sent a publickey packet, wait for reply
debug1: Server accepts key: pkalg ssh-rsa blen 279
debug2: input_userauth_pk_ok: fp 31:cc:3b:fa:xx:xx:xx:a1:ae:d6:21:97:62:68:fa:f0
debug3: sign_and_send_pubkey
debug1: PEM_read_PrivateKey failed
debug1: read PEM private key done: type <unknown>

ssh -vvv asus 成功

debug1: Next authentication method: publickey
debug1: Offering RSA public key: C:/cygwin/home/*user*/.ssh/id_rsa
debug3: send_pubkey_test
debug2: we sent a publickey packet, wait for reply
debug1: Server accepts key: pkalg ssh-rsa blen 279
debug2: input_userauth_pk_ok: fp 31:cc:3b:fa:xx:xx:xx:a1:ae:d6:21:97:62:68:fa:f0
debug3: sign_and_send_pubkey: RSA 31:cc:3b:fa:xx:xx:xx:a1:ae:d6:21:97:62:68:fa:f0
debug1: Authentication succeeded (publickey).
Authenticated to *router* (via proxy).

debug3: sign_and_send_pubkey 似乎有问题。


其他数据

~/ 的 chmod 为 755,id_rsa.pub 的 chmod 为 644,id_rsa 为 600

【问题讨论】:

    标签: git ssh cygwin ssh-tunnel dd-wrt


    【解决方案1】:

    免责声明:如果允许这种连接,请让您的安全人员为您启用它。如果不允许,而您仍然使用一些隧道来规避公司的安全概念,您将遇到很多麻烦!请注意。

    您已经成功连接到您的路由器。在这种情况下,我会使用

    ProxyCommand ssh router nc -w1 %h %p
    

    在您的 .ssh/config 中。

    这将首先打开到您的路由器的 ssh 连接并连接到实际的目标主机,然后启动实际的 ssh 连接。 git 也应该适用于这种设置。

    【讨论】:

    • 感谢您迄今为止的警告和帮助。我会尽快试试。你能否详细说明一下。比如-w1到底是什么,我什么也没找到。
    • 哦,不知道man ssh_config。你为什么选择这种方法而不是ssh -L?
    • ssh -L 只会打开一个本地套接字,您必须明确使用指定localhost。 - 这应该可行,但需要两个手动步骤,而上述解决方案是完全透明的。 ssh -D 是另一种选择。在这种情况下,您必须将应用程序配置为使用本地 socks 代理。
    • 提一下:我与 IT 部门核实过。他们告诉我没关系......但他们仍然不会为我打开端口:) 此外,我设法通过 ssh 连接到 abritray 服务器,甚至 git@bitbucket.org,但 git push/pull 命令仍然无法正常工作,两者都有错误我添加到问题中
    猜你喜欢
    • 2021-10-06
    • 1970-01-01
    • 2016-07-27
    • 1970-01-01
    • 1970-01-01
    • 2013-10-16
    • 2011-02-01
    • 2016-09-09
    • 2014-09-03
    相关资源
    最近更新 更多