Mac 让sudo命令走代理

在Mac OS中,在终端中利用命令

export http_proxy=http://127.0.0.1:1087;export https_proxy=http://127.0.0.1:1087;

让当前终端走Shadowsockes的代理,但是通过sudo执行仍然走的是原来的老路。
比如使用pip命令就会出现这样的情况:

sudo pip install frida-tools

Downloading https://files.pythonhosted.org/packages/d1/b0/1a6c262da35c779dd79550137aa7c298a424987240a28792ec5ccf48f848/prompt_toolkit-1.0.15-py2-none-any.whl (247kB)
    45% |██████████████▌                 | 112kB 1.2kB/s eta 0:01:50Exception:
Traceback (most recent call last):
..............
ReadTimeoutError: HTTPSConnectionPool(host='files.pythonhosted.org', port=443): Read timed out.

WTF!!!!!

这个时候,你就会发现这篇文章的价值了。。
解决方法是:

打开访达(finder),选择前往-前往文件夹,输入/etc
找到sudoers文件,用Sublime Text(一个非常好用的文本编辑器)打开,然后加入

Defaults env_keep += "http_proxy https_proxy no_proxy"

至于加在哪里,你打开这个文件之后自己就能看出来了。。。
保存并退出。
这个文件是只读的,需要右键-显示简介-改权限,另外一定不要用系统的文本编辑,不然就算改了权限它也不会让你写该文件,用Sublime Text,改完之后直接command+S保存,。

新建终端,还是要先让终端走代理,然后再来一遍pip:

sudo pip install frida-tools

Downloading https://files.pythonhosted.org/packages/d1/b0/1a6c262da35c779dd79550137aa7c298a424987240a28792ec5ccf48f848/prompt_toolkit-1.0.15-py2-none-any.whl (247kB)
    100% |████████████████████████████████| 256kB 872kB/s 
Requirement already satisfied: pygments<3.0.0,>=2.0.2 in /usr/local/lib/python2.7/site-packages (from frida-tools) (2.2.0)
Requirement already satisfied: wcwidth in /usr/local/lib/python2.7/site-packages (from prompt-toolkit<2.0.0,>=0.57->frida-tools) (0.1.7)
Requirement already satisfied: six>=1.9.0 in /usr/local/lib/python2.7/site-packages (from prompt-toolkit<2.0.0,>=0.57->frida-tools) (1.11.0)
Installing collected packages: prompt-toolkit
  Found existing installation: prompt-toolkit 2.0.3
    Uninstalling prompt-toolkit-2.0.3:
      Successfully uninstalled prompt-toolkit-2.0.3
Successfully installed prompt-toolkit-1.0.15

这速度简直是天壤之别啊。。

猜你喜欢

转载自blog.csdn.net/youshaoduo/article/details/81134000