如何通过SOCKS代理运行fabric脚本?
我有一个SOCKS代理,它连接到一个网关服务器。这个代理是通过在我的ssh_config
文件中设置一个主机定义来创建的,使用了DynamicForward localhost:9876
。为了通过SSH连接到远程服务器,我又设置了另一个主机定义,使用ProxyCommand /usr/bin/nc -x localhost:9876 %h %p
,这一切都运行得很好。
不过,我的fabric脚本需要连接到那个远程服务器。我该如何告诉它在连接时使用SOCKS代理呢?
4 个回答
0
你可以使用tsocks和OpenSSH客户端自带的功能来创建SOCKS隧道。这需要一些配置,但效果很好。下面是我在Ubuntu 10.04上开始的步骤。
# Install the tsocks library and shell script.
sudo apt-get install tsocks
# Configure the range of IP addresses you need access to.
sudo nano /etc/tsocks.conf
# Use the OpenSSH client to create a socks proxy (stepping
# stones are hosts used to gain access to private subnets).
ssh -D 1080 stepping.stone
# Now connect to any given address in your configured range.
# tsocks will intercept the connection and route it using
# the SOCKS proxy we created with the previous command.
tsocks ssh 1.2.3.4
Fabric在没有VPN连接的情况下无法工作,这让我很头疼,所以这个解决方案非常不错;只需要对一个主机有SSH访问权限就可以了。