{"id":24678837,"url":"https://github.com/islishude/shell-proxy","last_synced_at":"2025-10-08T11:31:26.093Z","repository":{"id":43908340,"uuid":"118133436","full_name":"islishude/shell-proxy","owner":"islishude","description":"在命令行工具中使用HTTP/SOCK5代理","archived":true,"fork":false,"pushed_at":"2022-05-28T01:42:21.000Z","size":25,"stargazers_count":51,"open_issues_count":0,"forks_count":9,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-04-05T18:52:28.675Z","etag":null,"topics":["http-proxy","proxy","shadowsocks"],"latest_commit_sha":null,"homepage":"","language":"Shell","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/islishude.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-01-19T14:15:32.000Z","updated_at":"2025-04-02T14:31:02.000Z","dependencies_parsed_at":"2022-08-26T03:00:25.450Z","dependency_job_id":null,"html_url":"https://github.com/islishude/shell-proxy","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/islishude/shell-proxy","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/islishude%2Fshell-proxy","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/islishude%2Fshell-proxy/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/islishude%2Fshell-proxy/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/islishude%2Fshell-proxy/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/islishude","download_url":"https://codeload.github.com/islishude/shell-proxy/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/islishude%2Fshell-proxy/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":278934167,"owners_count":26071364,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-10-08T02:00:06.501Z","response_time":56,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["http-proxy","proxy","shadowsocks"],"created_at":"2025-01-26T13:18:35.006Z","updated_at":"2025-10-08T11:31:25.813Z","avatar_url":"https://github.com/islishude.png","language":"Shell","funding_links":[],"categories":[],"sub_categories":[],"readme":"# 在命令行工具中使用代理\n\n## Mac 和 Linux\n\n类 Unix 环境下设置代理特别简单，只要在用户家目录下的 `.bashrc` 或 `.bash_profile` （ZSH 对应 `.zshrc` 以及 `.zsh_profile`）设置 `http_proxy` 和 `https_proxy` 环境变量到代理地址即可，如下所示，其中 `$url` 就是代理地址。\n\n```bash\n# 代理设置\nurl=http://127.0.0.1:7890\n# 如果代理失效的话直接运行 poff 即可断开 proxy\nalias poff='unset http_proxy;unset https_proxy'\n# 快捷方式打开\nalias pon='export http_proxy=$url; export https_proxy=$url'\n```\n\n这里我设置了别名，需要使用代理的时候直接运行 `pon` 即可打开代理，而运行 `poff` 则关闭代理。\n\n或者你可以直接可以设置只要打开 Termial 就使用代理的话去掉 `alias` 命令即可。\n\n```bash\nexport https_proxy=http://127.0.0.1:7890 http_proxy=http://127.0.0.1:7890\n```\n\n这里我使用的是 clashx ，所以这里的 `url` 是 `http://127.0.0.1:7890`。如果你需要自定义端口可以打开 ClashX Dashboard Setting 配置相关端口即可。\n\n在 Linux 下有个比设置 http 和 https 代理有个更简单的，可以直接设置 `export ALL_PROXY=socks5://127.0.0.1:7890` 就行了。\n\n最后测试一下连接，如果出现以下情况即说明设置成功。\n\n```console\n$ curl -I https://google.com\nHTTP/1.1 200 Connection established\n\nHTTP/2 301\nlocation: https://www.google.com/\ncontent-type: text/html; charset=UTF-8\ndate: Thu, 28 Feb 2019 03:37:48 GMT\nexpires: Sat, 30 Mar 2019 03:37:48 GMT\ncache-control: public, max-age=2592000\nserver: gws\ncontent-length: 220\nx-xss-protection: 1; mode=block\nx-frame-options: SAMEORIGIN\nalt-svc: quic=\":443\"; ma=2592000; v=\"44,43,39\"\n```\n\n由于 ClashX 可以对系统内直接配置代理，一般不需要再次在 Terminal 中额外配置。\n\n## 忽略对网段的代理\n\n我们可以对某些网段进行忽略代理设置，比如本地 127.0.0.1 等等。\n\n设置这个也很简单，\n\n```\nexport NO_PROXY=127.0.0.1,10.96.0.0/12,192.168.99.0/24,192.168.39.0/24\n```\n\n## Windows\n\n如果你使用 Windows PowerShell 的话，那么需要使用下面的方式：\n\n```bash\n# 查看\nset http_proxy\n# 设置\nset http_proxy=YOUR-PROXY\nset https_proxy=YOUR-PROXY\n# 删除\nset http_proxy=\n```\n\n在 Windows 下使用 Git Bash 则配置方式和 Mac/Linux 一致，不过需要注意的需要在 `.bash_profile` 而不是 `.bashrc` 中进行配置。\n\n因为如果你留意的话在每次打开 Git Bash 的时候回一闪而过 login 的字样，而 `.bashrc` 在每次打开命令行工具时就加载，而 `.bash_profile` 仅在用户登录时候加载一次，所以每次打开 GitBash 的行为就是登录用户。\n\n## VSCode\n\n打开设置，选择 Applicaion-Proxy，注意这里保持 `Proxy Strict SSL`，关闭可能导致某些插件不能正常工作。\n\n![image](https://user-images.githubusercontent.com/24730006/54330200-c2702180-464f-11e9-8a67-ad117e2ea0fb.png)\n\n在 VSCode Windows 下默认使用 PowerShell 或者 CMD 命令工具，当然也可以设置成 GitBash 的。方法很简单，使用快捷键 \u003ckbd\u003eCtrl\u003c/kbd\u003e + \u003ckbd\u003eShift\u003c/kbd\u003e + \u003ckbd\u003ep\u003c/kbd\u003e，然后输入 `shell` 选择默认 shell 命令即可。\n\n在这里 vscode 使用正则限制了 proxy url，只能输入 http/https 开头的地址，但是是可以输入并使用 socks5，只需要点击右上角 `{}` 符号切换到 json 配置界面设置 socks5 开头的地址，然后忽略错误就可以了。\n\n## Git\n\n```\n# 设置 git 的代理相关设置\ngit config –global http.proxy http://127.0.0.1:1080\ngit config –global https.proxy http://127.0.0.1:1080\n# 或者使用 sock5\ngit config --global http.proxy socks5://127.0.0.1:1080\ngit config --global https.proxy socks5://127.0.0.1:1080\n\n# 取消 git 的代理相关设置\ngit config –global –unset http.proxy\n# 取消 git 的代理相关设置\ngit config –global –unset https.proxy\n```\n\n\n## 虚拟机\n\n在虚拟机中可以开启 ss 然后设置代理，基本流程和上述一致。但是如果想要连接宿主机的代理服务的话也很简单。首先在宿主机中的 ss 设置允许其它设备访问，然后代理设置成宿主机的 IP 即可。虚拟机的网络设置最好设置成桥接模式，这样主机和虚拟机就会在一个网络段，可以互相直连。\n\n## ClashX\n\n- 项目 https://github.com/yichengchen/clashX\n- 规则推荐 https://github.com/Loyalsoldier/clash-rules\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fislishude%2Fshell-proxy","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fislishude%2Fshell-proxy","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fislishude%2Fshell-proxy/lists"}