如何通过 SOCKS 通过 SSH 隧道传输 HTTP?

wti*_*ing 21 linux ssh proxy socks-proxy

这应该是一个很容易解决的问题,但由于某种原因它对我不起作用。

ssh vps 工作正常(我使用身份验证密钥)

我使用以下命令设置隧道:

ssh -C2TNv -D 8080 vps

然后我修改 Firefox 网络设置:

  • 手动配置
    • http 代理:本地主机,端口:8080
    • 将此代理服务器用于所有协议
    • 袜子 v5
  • 关于:配置
    • network.proxy.socks_remote_dns: 真

终端输出:

$ ssh -C2TNv -D 8080 vps
OpenSSH_6.0p1, OpenSSL 1.0.1a 19 Apr 2012
debug1: Reading configuration data /home/ting/.ssh/config
debug1: /home/ting/.ssh/config line 47: Applying options for vps
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: Connecting to vps.server.com [1.1.1.1] port 22.
debug1: Connection established.
debug1: identity file /home/ting/.ssh/id_rsa type 1
debug1: identity file /home/ting/.ssh/id_rsa-cert type -1
debug1: Remote protocol version 2.0, remote software version OpenSSH_5.5p1 Debian-6+squeeze1
debug1: match: OpenSSH_5.5p1 Debian-6+squeeze1 pat OpenSSH_5*
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_6.0
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: server->client aes128-ctr hmac-md5 zlib@openssh.com
debug1: kex: client->server aes128-ctr hmac-md5 zlib@openssh.com
debug1: SSH2_MSG_KEX_DH_GEX_REQUEST(1024<1024<8192) sent
debug1: expecting SSH2_MSG_KEX_DH_GEX_GROUP
debug1: SSH2_MSG_KEX_DH_GEX_INIT sent
debug1: expecting SSH2_MSG_KEX_DH_GEX_REPLY
debug1: Server host key: RSA <removed>
debug1: Host 'vps.server.com' is known and matches the RSA host key.
debug1: Found key in /home/ting/.ssh/known_hosts:10
debug1: ssh_rsa_verify: signature correct
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug1: SSH2_MSG_NEWKEYS received
debug1: Roaming not allowed by server
debug1: SSH2_MSG_SERVICE_REQUEST sent
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug1: Authentications that can continue: publickey,password
debug1: Next authentication method: publickey
debug1: Offering RSA public key: /home/ting/.ssh/id_rsa
debug1: Server accepts key: pkalg ssh-rsa blen 279
debug1: Enabling compression at level 6.
debug1: Authentication succeeded (publickey).
Authenticated to vps.server.com ([1.1.1.1]:22).
debug1: Local connections to LOCALHOST:8080 forwarded to remote address socks:0
debug1: Local forwarding listening on ::1 port 8080.
debug1: channel 0: new [port listener]
debug1: Local forwarding listening on 127.0.0.1 port 8080.
debug1: channel 1: new [port listener]
debug1: Requesting no-more-sessions@openssh.com
debug1: Entering interactive session.
Run Code Online (Sandbox Code Playgroud)

然后我尝试使用 Firefox 访问一个站点,SSH 输出:

debug1: Connection to port 8080 forwarding to socks port 0 requested.
debug1: channel 2: new [dynamic-tcpip]
debug1: channel 2: free: dynamic-tcpip, nchannels 3
debug1: Connection to port 8080 forwarding to socks port 0 requested.
debug1: channel 2: new [dynamic-tcpip]
debug1: channel 2: free: dynamic-tcpip, nchannels 3
Run Code Online (Sandbox Code Playgroud)

尽管代理似乎可以正常工作,但使用 Firefox 访问任何站点都会返回错误“连接已重置”。

bar*_*lop 28

您带 -D 的 SSH 命令很好(因此 SOCKS 将建立隧道,它只是通过 HTTP 连接到 SOCKS,您必须解决这个问题)

我得到了很好的输出

curl --socks5 127.0.0.1:8080 http://blah
Run Code Online (Sandbox Code Playgroud)

但如果我这样做,我会得到同样的错误输出

 curl --proxy 127.0.0.1:8080 http://blah
Run Code Online (Sandbox Code Playgroud)

因此,firefox 正在连接,就好像它是一个 HTTP 代理

看着火狐窗口

手动配置 是

你说你勾选了“为所有协议使用这个代理服务器”这是一个完全错误的举动!您想输入 SOCKS 代理,如果您这样做,则 SOCKS 框会变为空/变灰,您只能输入 HTTP 代理。

所以不要勾选那个。

然后,输入socks代理ip。

并删除它说没有代理的地方 127.0.0.1,localhost 。如果它说,这是默认的。

  • 谢谢你的回答。但是,我通过清除 Firefox 代理配置屏幕中的 ** 一切** 来使其正常工作,* 除外 * `SOCKS Host` 字段。如果我在“HTTP 代理”字段中添加了任何内容,它就会停止工作。 (15认同)