1. 程式人生 > >Mac 讓sudo命令走代理

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

這速度簡直是天壤之別啊。。