Ubuntu让终端走代理http&ssh

原创
2019/06/23 20:07
阅读数 7.5W

Ubuntu让终端走代理http&ssh

http代理

  • 方法1
export http_proxy=http://localhost:port
export https_proxy=http://localhost:port
export all_proxy=socks5://127.0.0.1:7890

以使用s代理为例,s的代理端口为1080,那么应该设置为
export https_proxy=http://127.0.0.1:7890 http_proxy=http://127.0.0.1:7890 all_proxy=socks5://127.0.0.1:7890

或者直接设置ALL_PROXY,http和https都走代理了
export ALL_PROXY=socks5://127.0.0.1:7890

删除
unset ALL_PROXY

如果代理服务器需要登陆,这时可以直接把用户名和密码写进去
http_proxy="http://user:password@localhost:port"
  • 方法2
利用proxychains在终端使用socks5代理

安装
Ubuntu下就叫 proxychains4
sudo apt install proxychains4

Mac下叫 proxychains-ng
brew install proxychains-ng

安装完成之后可以直接使用 proxychains4 命令

配置文件
Mac
/usr/local/etc/proxychains.conf

Ubuntu
/etc/proxychains.conf

找到配置文件,直接到最后一行的
[ProxyList]

注释掉 
socks4     127.0.0.1 9050

添加
socks5     127.0.0.1 7890

就可以用了,测试案例:
proxychains4 curl cip.cc

ssh代理

通过修改ssh配置文件同时将整个系统的ssh连接走代理

nc 这个工具一般的Ubuntu系统都带的有.没有的话apt insttall nc,Mac使用brew install nc

  • 添加代理
# ServerAliveInterval定时向服务器发送消息以保持连接,防止不操作而断开.需要的时候才添加
echo "ProxyCommand nc -X 5 -x 127.0.0.1:1080 %h %p" >> ~/.ssh/config
echo "ServerAliveInterval 30" >> ~/.ssh/config
  • 取消代理
sed '/ProxyCommand/d' ~/.ssh/config  > ~/.ssh/config.bk && mv ~/.ssh/config.bk   ~/.ssh/config
# 或者
sed '/ProxyCommand/d;/ServerAliveInterval/d' ~/.ssh/config  > ~/.ssh/config.bk && mv ~/.ssh/config.bk   ~/.ssh/config
展开阅读全文
加载中

作者的其它热门文章

打赏
0
0 收藏
分享
打赏
0 评论
0 收藏
0
分享
返回顶部
顶部