Firefox 47.0 / Kubuntu 16.04 上的 ssh-tunneled SOCKS 代理连接被拒绝

Firefox 47.0 / Kubuntu 16.04 上的 ssh-tunneled SOCKS 代理连接被拒绝

我在使用 Firefox 通过隧道 SOCKS 代理连接到网站时遇到困难。SOCKS4/SOCKS5 没有区别。

我设置了隧道

ssh -D 1234[电子邮件保护]

然后将 Firefox 的 SOCKS 代理指向 tcp/1234 上的 localhost。

这里要注意的一个关键点是,我设置的隧道位于一个远程服务器上,多年来我一直为此目的使用它。我已通过它代理了 FF 和其他浏览器,在所有主要操作系统上的十几个或更多不同平台上进行了数千次会话。一旦我让它工作起来,它总是运行顺畅。然而,在这个特定的 FF 实例上,我遇到了奇怪且间歇性的问题。

问题是 FF 似乎并不“想”建立连接。我输入 URL 或点击链接,然后即刻出现“无法连接”/“Firefox 无法与服务器建立连接...”当我说“立即”时,我的意思是这会在一瞬间弹回到我面前。

于是我点击“再试一次”或小重新加载箭头。我尽可能快地一次又一次地这样做。经过几次尝试——有时 3-4 次,有时多达 15-20 次——我得到了连接并且一切正常!因此隧道/SOCKS连接可用,只是 FF 拒绝使用它,直到它被迫这样做。一旦我获得连接,进一步的重新加载不会导致它丢失。

我有一些附加组件,但是 a) 我已经选择性地禁用它们,没有任何帮助,并且 b) 我(当然)尝试了安全模式。没有任何变化。

有什么建议么?

答案1

我每天上班时都必须使用代理才能连接到防火墙另一侧的服务器。我还使用 Firefox、Chrome 和 Ubuntu 16.04。


编辑: 我忘了其中的一部分。我必须在 ssh 配置文件中添加超时,否则我的隧道将超时,并且我会失去连接。一旦我添加了以下内容,我的连接就会保持打开状态:

添加~/.ssh/config以下信息(如果该文件不存在,则创建它。)。这将每 15 秒向您的隧道发送一次服务器保持活动。

Host *
ServerAliveInterval 15

我使用以下命令打开隧道连接:

ssh -CfND 1234 username@proxyhost

然后在 Firefox 下连接设置在里面手动代理配置我只填写SOCKS 主机:使用 127.0.0.1 和港口:1234.然后我确保袜子v5已选定。 另请注意,我在“无代理:”框中没有任何内容。

我能够通过这种方式毫无问题地连接到我的主机。

在此处输入图片描述

然后,对于 Chrome,我运行命令行,这样每次我想通过代理时,就不必将设置设置为 Chrome,这样就无需代理。要将 Chrome 连接到代理,我运行以下行:

nohup google-chrome-stable --proxy-server="socks5://127.0.0.1:1234" & > /dev/null 2>&1

from ssh manpage

 -C      Requests compression of all data (including stdin, stdout,
         stderr, and data for forwarded X11, TCP and UNIX-domain connec‐
         tions).  The compression algorithm is the same used by gzip(1),
         and the “level” can be controlled by the CompressionLevel option
         for protocol version 1.  Compression is desirable on modem lines
         and other slow connections, but will only slow down things on
         fast networks.  The default value can be set on a host-by-host
         basis in the configuration files; see the Compression option.

 -f      Requests ssh to go to background just before command execution.
         This is useful if ssh is going to ask for passwords or
         passphrases, but the user wants it in the background.  This
         implies -n.  The recommended way to start X11 programs at a
         remote site is with something like ssh -f host xterm.

 -N      Do not execute a remote command.  This is useful for just for‐
         warding ports.

 -D [bind_address:]port
         Specifies a local “dynamic” application-level port forwarding.
         This works by allocating a socket to listen to port on the local
         side, optionally bound to the specified bind_address.  Whenever a
         connection is made to this port, the connection is forwarded over
         the secure channel, and the application protocol is then used to
         determine where to connect to from the remote machine.  Currently
         the SOCKS4 and SOCKS5 protocols are supported, and ssh will act
         as a SOCKS server.  Only root can forward privileged ports.
         Dynamic port forwardings can also be specified in the configura‐
         tion file.

希望这可以帮助!

答案2

不幸的是,这个问题是间歇性的,这让我的故障排除工作很受困扰。@Terrance 在上面给出的答案,我将其标记为答案,实际上对我来说并不是解决问题的方法。它似乎工作,以及实际上工作了一段时间。然后我又遇到了问题。有时停止我的 ssh 会话并重新启动它可以解决问题——在一段时间内——有时重新启动没有任何作用。

提到的建议这个主题在其他地方——即在浏览器的代理设置——同样似乎有所作为,但最终却毫无效果。我之前回答说,这是浏览器连接成功与否的关键区别,但这又为时过早。我的浏览器在通过隧道与网站建立连接时,仍然会遇到间歇性问题。

我现在已经获得了足够的额外经验来解决这个问题,并且我在下面提到的解决方案中,我对我的结论有相当的信心OpenSSH 本身存在某种短暂超时错误。顺便说一句,我的版本是

OpenSSH_7.2p2 Ubuntu-4ubuntu1,OpenSSL 1.0.2g-fips 2016 年 3 月 1 日

我基于以下事实得出这一结论:a)该问题显然与浏览器无关(已在 Firefox、Chromium 和 w3m 中验证);b)使用备用 ssh 客户端可以可靠地解决该问题。

我下载了源代码并构建并安装了PuTTY(来自此链接)。注意:请确保安装虚拟包 gtkgl-dev,以便 PuTTY 源可以找到头文件。然后我像过去在 Windows 中多次设置它一样对其进行设置,它已经运行了大约两天。零故障。

我相信这是修复,并且当前 OpenSSH 中存在错误。我将努力对此进行报告。

为了回答这个问题,我选择我自己的答案作为答案,尽管上面@Terrence的回答仍然非常有用。

相关内容