mirror of
https://github.com/andatoshiki/toshiki-notebook.git
synced 2026-06-06 09:16:45 +00:00
80 lines
48 KiB
JavaScript
80 lines
48 KiB
JavaScript
import{_ as o}from"./chunks/PageInfo.vue_vue_type_script_setup_true_lang.250b3e56.js";import{_ as t,o as l,c as p,H as r,a as e,k as s,Q as n}from"./chunks/framework.b7580407.js";import"./chunks/commonjsHelpers.725317a4.js";const i="/assets/2023-11-04-03-15-12.77ab4cd9.png",c="/assets/2023-11-02-04-44-14.08b67c2b.png",h="/assets/2023-11-04-00-42-58.d7bf77fb.png",d="/assets/2023-11-04-01-32-28.da2149a9.png",y="/assets/2023-11-04-03-49-38.78c93d29.png",u="/assets/2023-11-04-04-27-59.3d817820.png",m="/assets/2023-11-04-05-01-04.fd5f8fb7.png",q=JSON.parse('{"title":"Proxies Configuration for Shells & Terminal","description":"","frontmatter":{"title":"Proxies Configuration for Shells & Terminal","author":"Anda Toshiki","date":"2023-11-02T00:00:00.000Z"},"headers":[],"relativePath":"development/proxy4shell-terminal.md","filePath":"development/proxy4shell-terminal.md","lastUpdated":1712080553000}'),f={name:"development/proxy4shell-terminal.md"},b=s("h1",{id:"proxies-configuration-for-shells-terminal",tabindex:"-1"},[e("Proxies Configuration for Shells & Terminal "),s("a",{class:"header-anchor",href:"#proxies-configuration-for-shells-terminal","aria-label":'Permalink to "Proxies Configuration for Shells & Terminal"'},"")],-1),g=n('<h2 id="tl-dr" tabindex="-1">TL;DR <a class="header-anchor" href="#tl-dr" aria-label="Permalink to "TL;DR""></a></h2><p>This article discusses the configuration of proxies for shells and terminals. It explains the advantages of using proxy servers to bypass network restrictions and surveillance. The article provides examples of the challenges faced when accessing foreign services and shows how to set up a proxy tunnel using the curl command. It also provides scripts and instructions for setting up proxy switches in different shell environments, such as zsh, bash, and Windows CMD and PowerShell. The article concludes with additional information on proxy configurations for applications like ssh and tips for working with authentication procedures.</p><h2 id="_1-background" tabindex="-1">1. Background <a class="header-anchor" href="#_1-background" aria-label="Permalink to "1. Background""></a></h2><p>Proxies or namely proxy servers are by far one of the most affordable or cost-effective option to establish a masked layer connection to bypass the network restrictions with the annoying surveillance tracked by a local network ISP as compared to a click-to-use VPN service, which generically requires more individual invest to protect themselves under the insecure internet environment nowadays. When a user resides within the environment where the local gateways of full, user-dominant open access towards the internet is censored or restricted with domestic network blockages by the country.</p><p align="center"><img src="'+i+'" width="100" height="100" align="center"></p>',5),v=n('<h2 id="_2-the-major-issue" tabindex="-1">2. The Major Issue <a class="header-anchor" href="#_2-the-major-issue" aria-label="Permalink to "2. The Major Issue""></a></h2><p>The majority of the issue still heavily preserves across the developmental fields which the layer of the blockage imposes limits on communicating with third-party, remote platforms such as <a href="https://github.com" target="_blank" rel="noreferrer">Github</a> or registries like <a href="https://npmjs.com" target="_blank" rel="noreferrer">NPM</a> for frontend developments that stores key packages or components, as a requirement during a pre-built phase of a project. Most of the time foreign services becomes completely inaccessible or fortunately users could reach the services during a possible ISP maintenance downtime but normally the potentiality is mere, or hardly none yet the load speed before TTL connection expires are objectively slow, shortly before the origin site DNS being spoofed again. The unpleasant experiences with the networking somewhat affects interest on development reduces by high percentages or it even strand some awesome projects ran ashore ultimately.</p><p>The following screenshots are a more direct representation to visualize the differences between the connection towards one of the most beloved search engine, <a href="https://google.com" target="_blank" rel="noreferrer">Google</a> with the following command via <code>curl</code>.</p><div class="language-sh vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">sh</span><pre class="shiki github-dark-dimmed vp-code-dark"><code><span class="line"><span style="color:#F69D50;">curl</span><span style="color:#ADBAC7;"> </span><span style="color:#6CB6FF;">-I</span><span style="color:#ADBAC7;"> </span><span style="color:#96D0FF;">google.com</span></span></code></pre><pre class="shiki github-light vp-code-light"><code><span class="line"><span style="color:#6F42C1;">curl</span><span style="color:#24292E;"> </span><span style="color:#005CC5;">-I</span><span style="color:#24292E;"> </span><span style="color:#032F62;">google.com</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br></div></div><blockquote><p>The command is used to fetch the headers of a URL or web page. When you run "curl -I" followed by a URL, the command sends an HTTP HEAD request to the specified URL and retrieves the HTTP headers of the response. This allows you to view the information contained in the response headers without requesting and downloading the entire content of the page. The headers typically include details like the server information, content type, content length, status codes, and more.</p></blockquote><p>The following screenshot from terminal indicates the the final output of the package availability received without losses on a bare unmasked network environment, which returns <code>FAIL</code> in the final connection after a dry run fails 11s after when the TTL expires the connection fails.</p><p><img src="'+c+`" alt=""></p><p>The next screenshot from terminal indicates a temporary proxy tunnel is established both in <code>http</code> and <code>https</code> protocol tunneled through a local proxy gateway at the local systemic IP address at <code>127.0.0.1</code> and exposes the proxy server at a mix of socks/https/http protocol port at <code>7890</code>, just simply with the traditional <code>export</code> method by setting up in the nonce, the command is given as followed.</p><div class="language-sh vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">sh</span><pre class="shiki github-dark-dimmed vp-code-dark"><code><span class="line"><span style="color:#F47067;">export</span><span style="color:#ADBAC7;"> http_proxy</span><span style="color:#F47067;">=</span><span style="color:#96D0FF;">http://127.0.0.1:7890</span></span>
|
||
<span class="line"><span style="color:#F47067;">export</span><span style="color:#ADBAC7;"> https_proxy</span><span style="color:#F47067;">=</span><span style="color:#ADBAC7;">$http_proxy</span></span></code></pre><pre class="shiki github-light vp-code-light"><code><span class="line"><span style="color:#D73A49;">export</span><span style="color:#24292E;"> http_proxy</span><span style="color:#D73A49;">=</span><span style="color:#032F62;">http://127.0.0.1:7890</span></span>
|
||
<span class="line"><span style="color:#D73A49;">export</span><span style="color:#24292E;"> https_proxy</span><span style="color:#D73A49;">=</span><span style="color:#24292E;">$http_proxy</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br><span class="line-number">2</span><br></div></div><p>And then we re-enter the same command with <code>curl</code> from above; surprisingly, the header responses returned <code>TTP/1.1 200 OK</code>, thus the conclusion drawn here is the proxy server we launched was successfully up and running with tunneled access towards foreign sites without restrictions! Hooray!</p><p><figure><img src="`+h+`" alt="" title="Curl in action with successful response header from Google"><figcaption align="center"><small>◎ Curl in action with successful response header from Google</small></figcaption></figure></p><p>Since each proxy configuration might varies atop of the user preferred client, not including ShadowRocket, Clash, V2ray or other proprietary softwares that are licensed either behind a paywall to run with; or simply expensive to purchase a subscription; the proxy ports forwarded varies alongside the changes amongst clients. But the overall approach taken into the account still remains the same with the following traditional formats, the local IP of the machine (normally <code>127.0.0.1</code>) followed after with the specified ports. In the scenario of the article is referenced as example, I chose Clash (in spite the entire Clash project repository as well as its affiliated forked projects are being taken down by anonymous reasons by either archiving the overall projects or simply shutting down due to possible legal actions or political reasons regarding the country of residency of various developers).</p><div class="language-sh vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">sh</span><pre class="shiki github-dark-dimmed vp-code-dark"><code><span class="line"><span style="color:#768390;"># http protocal</span></span>
|
||
<span class="line"><span style="color:#F69D50;">http://127.0.0.1:7890</span></span>
|
||
<span class="line"><span style="color:#768390;"># https protocal</span></span>
|
||
<span class="line"><span style="color:#F69D50;">https://127.0.0.1:7890</span></span></code></pre><pre class="shiki github-light vp-code-light"><code><span class="line"><span style="color:#6A737D;"># http protocal</span></span>
|
||
<span class="line"><span style="color:#6F42C1;">http://127.0.0.1:7890</span></span>
|
||
<span class="line"><span style="color:#6A737D;"># https protocal</span></span>
|
||
<span class="line"><span style="color:#6F42C1;">https://127.0.0.1:7890</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br></div></div><h3 id="_2-1-kill-the-complexities-unleash-the-simplicity" tabindex="-1">2.1: Kill the Complexities; Unleash the Simplicity! <a class="header-anchor" href="#_2-1-kill-the-complexities-unleash-the-simplicity" aria-label="Permalink to "2.1: Kill the Complexities; Unleash the Simplicity!""></a></h3><p>But, the logic routes to the central question on: <strong>How can we simplify the course of action on setting up proxies without manually run <code>export</code> command every single time we wish to use?</strong> Below is a simple approach by aliasing a shortcut code to a proxy switch script amended towards your shell configuration profile that initializes on every session startups, in this case I uses zsh since it's integrated as the default shell on macOS since the release of macOS Catalina, yet it's one of my most familiar and favored shell when was using other OS as well.</p><p>Though some people might use autosuggestion extensions as third-party shell features to automatically predict the command completion after a code piece is inputted such as <code>zsh-autosuggestion</code> plugin or fan of fish shell users has the native privilege of auto completions but I personally not fond of such featured integration since it might decelerate the load speed of an active session; I prefer stick tightly with original shell.</p><div class="language-sh vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">sh</span><pre class="shiki github-dark-dimmed vp-code-dark"><code><span class="line"><span style="color:#768390;"># open your shell profile with an preferred editor</span></span>
|
||
<span class="line"><span style="color:#F69D50;">$</span><span style="color:#ADBAC7;"> </span><span style="color:#96D0FF;">vim</span><span style="color:#ADBAC7;"> </span><span style="color:#96D0FF;">~/.zshrc</span></span>
|
||
<span class="line"></span>
|
||
<span class="line"><span style="color:#768390;"># session proxy switch shortcut</span></span>
|
||
<span class="line"><span style="color:#F47067;">function</span><span style="color:#ADBAC7;"> </span><span style="color:#DCBDFB;">proxy_on</span><span style="color:#ADBAC7;">() {</span></span>
|
||
<span class="line"><span style="color:#ADBAC7;"> </span><span style="color:#F47067;">export</span><span style="color:#ADBAC7;"> http_proxy</span><span style="color:#F47067;">=</span><span style="color:#96D0FF;">http://127.0.0.1:7890</span></span>
|
||
<span class="line"><span style="color:#ADBAC7;"> </span><span style="color:#F47067;">export</span><span style="color:#ADBAC7;"> https_proxy</span><span style="color:#F47067;">=</span><span style="color:#ADBAC7;">$http_proxy</span></span>
|
||
<span class="line"><span style="color:#ADBAC7;"> </span><span style="color:#6CB6FF;">echo</span><span style="color:#ADBAC7;"> </span><span style="color:#6CB6FF;">-e</span><span style="color:#ADBAC7;"> </span><span style="color:#96D0FF;">"global proxy for the current terminal session has turned on"</span></span>
|
||
<span class="line"><span style="color:#ADBAC7;">}</span></span>
|
||
<span class="line"></span>
|
||
<span class="line"><span style="color:#F47067;">function</span><span style="color:#ADBAC7;"> </span><span style="color:#DCBDFB;">proxy_off</span><span style="color:#ADBAC7;">() {</span></span>
|
||
<span class="line"><span style="color:#ADBAC7;"> </span><span style="color:#6CB6FF;">unset</span><span style="color:#ADBAC7;"> </span><span style="color:#96D0FF;">http_proxy</span><span style="color:#ADBAC7;"> </span><span style="color:#96D0FF;">https_proxy</span></span>
|
||
<span class="line"><span style="color:#ADBAC7;"> </span><span style="color:#6CB6FF;">echo</span><span style="color:#ADBAC7;"> </span><span style="color:#6CB6FF;">-e</span><span style="color:#ADBAC7;"> </span><span style="color:#96D0FF;">"global proxy for the current terminal session has turned off"</span></span>
|
||
<span class="line"><span style="color:#ADBAC7;">}</span></span>
|
||
<span class="line"></span>
|
||
<span class="line"><span style="color:#768390;"># restart your terminal with a new session or reload the config</span></span>
|
||
<span class="line"><span style="color:#F69D50;">$</span><span style="color:#ADBAC7;"> </span><span style="color:#96D0FF;">source</span><span style="color:#ADBAC7;"> </span><span style="color:#96D0FF;">~/.zshrc</span></span></code></pre><pre class="shiki github-light vp-code-light"><code><span class="line"><span style="color:#6A737D;"># open your shell profile with an preferred editor</span></span>
|
||
<span class="line"><span style="color:#6F42C1;">$</span><span style="color:#24292E;"> </span><span style="color:#032F62;">vim</span><span style="color:#24292E;"> </span><span style="color:#032F62;">~/.zshrc</span></span>
|
||
<span class="line"></span>
|
||
<span class="line"><span style="color:#6A737D;"># session proxy switch shortcut</span></span>
|
||
<span class="line"><span style="color:#D73A49;">function</span><span style="color:#24292E;"> </span><span style="color:#6F42C1;">proxy_on</span><span style="color:#24292E;">() {</span></span>
|
||
<span class="line"><span style="color:#24292E;"> </span><span style="color:#D73A49;">export</span><span style="color:#24292E;"> http_proxy</span><span style="color:#D73A49;">=</span><span style="color:#032F62;">http://127.0.0.1:7890</span></span>
|
||
<span class="line"><span style="color:#24292E;"> </span><span style="color:#D73A49;">export</span><span style="color:#24292E;"> https_proxy</span><span style="color:#D73A49;">=</span><span style="color:#24292E;">$http_proxy</span></span>
|
||
<span class="line"><span style="color:#24292E;"> </span><span style="color:#005CC5;">echo</span><span style="color:#24292E;"> </span><span style="color:#005CC5;">-e</span><span style="color:#24292E;"> </span><span style="color:#032F62;">"global proxy for the current terminal session has turned on"</span></span>
|
||
<span class="line"><span style="color:#24292E;">}</span></span>
|
||
<span class="line"></span>
|
||
<span class="line"><span style="color:#D73A49;">function</span><span style="color:#24292E;"> </span><span style="color:#6F42C1;">proxy_off</span><span style="color:#24292E;">() {</span></span>
|
||
<span class="line"><span style="color:#24292E;"> </span><span style="color:#005CC5;">unset</span><span style="color:#24292E;"> </span><span style="color:#032F62;">http_proxy</span><span style="color:#24292E;"> </span><span style="color:#032F62;">https_proxy</span></span>
|
||
<span class="line"><span style="color:#24292E;"> </span><span style="color:#005CC5;">echo</span><span style="color:#24292E;"> </span><span style="color:#005CC5;">-e</span><span style="color:#24292E;"> </span><span style="color:#032F62;">"global proxy for the current terminal session has turned off"</span></span>
|
||
<span class="line"><span style="color:#24292E;">}</span></span>
|
||
<span class="line"></span>
|
||
<span class="line"><span style="color:#6A737D;"># restart your terminal with a new session or reload the config</span></span>
|
||
<span class="line"><span style="color:#6F42C1;">$</span><span style="color:#24292E;"> </span><span style="color:#032F62;">source</span><span style="color:#24292E;"> </span><span style="color:#032F62;">~/.zshrc</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br><span class="line-number">15</span><br><span class="line-number">16</span><br><span class="line-number">17</span><br></div></div><p>The proxy essentially provides two shortcut command function defined with <code>proxy_on</code> and <code>proxy_off</code>. he <code>proxy_on</code> function sets the environment variables <code>http_proxy</code> and <code>https_proxy</code> to <code>http://127.0.0.1:7890</code>, which is the default proxy port of the traditional clash protocol, <strong>here is where you could replace the IP with other remote proxy servers or ports of other local proxies</strong> .Enabling a global proxy for the current terminal session. Meanwhile the <code>proxy_off</code> function unsets (removes) the <code>http_proxy</code> and <code>https_proxy</code> environment variables, effectively turning off the global proxy for the current terminal session. When any of the both executed, the indicator message will be echoed on the terminal, see the following screenshot in action.</p><p><figure><img src="`+d+`" alt="" title="Enabling the shell session proxy with script"><figcaption align="center"><small>◎ Enabling the shell session proxy with script</small></figcaption></figure></p><p>After you reload your shell profile you can test out the scripted command yourself. To test whether the proxy has a successful setup after the proxy has been switched on, run <code>echo $http_proxy</code> or <code>https_proxy</code> with a dollar sign in front of the alias as an indicator for environmental variable, the third command as shown in the screenshot above, the command will simply print the configured variable value addressed to the specified alias. Contrarily, if your terminal returns the following resultant,</p><div class="language-sh vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">sh</span><pre class="shiki github-dark-dimmed vp-code-dark"><code><span class="line"><span style="color:#F69D50;">$</span><span style="color:#ADBAC7;"> </span><span style="color:#96D0FF;">proxy_on</span></span>
|
||
<span class="line"><span style="color:#F69D50;">zsh:</span><span style="color:#ADBAC7;"> </span><span style="color:#96D0FF;">command</span><span style="color:#ADBAC7;"> </span><span style="color:#96D0FF;">not</span><span style="color:#ADBAC7;"> </span><span style="color:#96D0FF;">found:</span><span style="color:#ADBAC7;"> </span><span style="color:#96D0FF;">proxy_on</span></span></code></pre><pre class="shiki github-light vp-code-light"><code><span class="line"><span style="color:#6F42C1;">$</span><span style="color:#24292E;"> </span><span style="color:#032F62;">proxy_on</span></span>
|
||
<span class="line"><span style="color:#6F42C1;">zsh:</span><span style="color:#24292E;"> </span><span style="color:#032F62;">command</span><span style="color:#24292E;"> </span><span style="color:#032F62;">not</span><span style="color:#24292E;"> </span><span style="color:#032F62;">found:</span><span style="color:#24292E;"> </span><span style="color:#032F62;">proxy_on</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br><span class="line-number">2</span><br></div></div><p>Then you will have to distinguish the exact shell you are currently on, the hereinafter content are mainly targeted towards novice learners whom are unable to track the shell types or configuration on particular operating systems. The configuration file for each shell varies their file names as well the location of storage; <strong>while Mac users could directly apply changes based on the instruction provided above if your system if Catalina or above</strong>. To know what exactly the active shell running, run,</p><div class="language-sh vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">sh</span><pre class="shiki github-dark-dimmed vp-code-dark"><code><span class="line"><span style="color:#F69D50;">$</span><span style="color:#ADBAC7;"> </span><span style="color:#96D0FF;">echo</span><span style="color:#ADBAC7;"> $SHELL</span></span></code></pre><pre class="shiki github-light vp-code-light"><code><span class="line"><span style="color:#6F42C1;">$</span><span style="color:#24292E;"> </span><span style="color:#032F62;">echo</span><span style="color:#24292E;"> $SHELL</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br></div></div><p>The returned string text will be the name of the current active shell, the following is a list of the possible shell profile config name affiliated with each shell; most of the config profile files should be lied under the <code>~</code> or the root/home folder of each operating system with a <code>dot</code> in front of the file names are inferred as hidden file or directory in most of the Unix-like systems, such as macOS, Ubuntu, Debian and etc, but some of the config file such as fish shell could locate in an isolated config directory. The usual format of a config file is as followed,</p><div class="language-shell vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">shell</span><pre class="shiki github-dark-dimmed vp-code-dark"><code><span class="line"><span style="color:#F47067;">~</span><span style="color:#ADBAC7;">/.zshrc</span></span></code></pre><pre class="shiki github-light vp-code-light"><code><span class="line"><span style="color:#D73A49;">~</span><span style="color:#24292E;">/.zshrc</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br></div></div><p>The following is a list of the most common shells with their possible profile file names that corresponded,</p><ul><li><code>/bin/bash</code> : <code>.bash_profile</code> or <code>.bashrc</code></li><li><code>/bin/zsh</code> : <code>.zprofile</code> or <code>.zshrc</code></li><li><code>/bin/fish</code>: <code> ~/.config/fish/config</code></li></ul><p>Still, the location might still varies, users might have to perform individual research to precisely locate their configuration file location, which is out of my jurisdiction of concerns (it's just evident action of procrastination and laziness, my apologies if none of the ones above fits your demand) <code>;)</code>.</p><p align="center"><img src="`+y+`" width="100" height="100" align="center"></p><p>For Unix-like users, after you have specified your shell as well as your config file name and locations, copy the following code chunk as command and paste it back into your terminal and run to apply permanent changes to the configuration.</p><div class="language-sh vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">sh</span><pre class="shiki github-dark-dimmed vp-code-dark"><code><span class="line"><span style="color:#F69D50;">cat</span><span style="color:#ADBAC7;"> </span><span style="color:#F47067;">>></span><span style="color:#ADBAC7;"> </span><span style="color:#96D0FF;">~/.zshrc</span><span style="color:#ADBAC7;"> </span><span style="color:#F47067;"><<</span><span style="color:#ADBAC7;"> </span><span style="color:#ADBAC7;">EOF</span></span>
|
||
<span class="line"><span style="color:#96D0FF;"># session proxy switch shortcut</span></span>
|
||
<span class="line"><span style="color:#96D0FF;">function proxy_on() {</span></span>
|
||
<span class="line"><span style="color:#96D0FF;"> export http_proxy=http://127.0.0.1:7890</span></span>
|
||
<span class="line"><span style="color:#96D0FF;"> export https_proxy=</span><span style="color:#ADBAC7;">$http_proxy</span></span>
|
||
<span class="line"><span style="color:#96D0FF;"> echo -e "global proxy for the current terminal session has turned on"</span></span>
|
||
<span class="line"><span style="color:#96D0FF;">}</span></span>
|
||
<span class="line"></span>
|
||
<span class="line"><span style="color:#96D0FF;">function proxy_off(){</span></span>
|
||
<span class="line"><span style="color:#96D0FF;"> unset http_proxy https_proxy</span></span>
|
||
<span class="line"><span style="color:#96D0FF;"> echo -e "global proxy for the current terminal session has turned off"</span></span>
|
||
<span class="line"><span style="color:#96D0FF;">}</span></span>
|
||
<span class="line"><span style="color:#ADBAC7;">EOF</span></span></code></pre><pre class="shiki github-light vp-code-light"><code><span class="line"><span style="color:#6F42C1;">cat</span><span style="color:#24292E;"> </span><span style="color:#D73A49;">>></span><span style="color:#24292E;"> </span><span style="color:#032F62;">~/.zshrc</span><span style="color:#24292E;"> </span><span style="color:#D73A49;"><<</span><span style="color:#24292E;"> </span><span style="color:#032F62;">EOF</span></span>
|
||
<span class="line"><span style="color:#032F62;"># session proxy switch shortcut</span></span>
|
||
<span class="line"><span style="color:#032F62;">function proxy_on() {</span></span>
|
||
<span class="line"><span style="color:#032F62;"> export http_proxy=http://127.0.0.1:7890</span></span>
|
||
<span class="line"><span style="color:#032F62;"> export https_proxy=</span><span style="color:#24292E;">$http_proxy</span></span>
|
||
<span class="line"><span style="color:#032F62;"> echo -e "global proxy for the current terminal session has turned on"</span></span>
|
||
<span class="line"><span style="color:#032F62;">}</span></span>
|
||
<span class="line"></span>
|
||
<span class="line"><span style="color:#032F62;">function proxy_off(){</span></span>
|
||
<span class="line"><span style="color:#032F62;"> unset http_proxy https_proxy</span></span>
|
||
<span class="line"><span style="color:#032F62;"> echo -e "global proxy for the current terminal session has turned off"</span></span>
|
||
<span class="line"><span style="color:#032F62;">}</span></span>
|
||
<span class="line"><span style="color:#032F62;">EOF</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br></div></div><p>The script above will write-in and install the proxy switch script and save the the content to the very end of the file. <strong>As a kindly reminder, if your shell is not <code>zsh</code> make sure to replace the string after <code>cat >></code> to the actual path of your profile as well as your proxy server IP and port to the actual functioning details to your own demand</strong>; then ultimately, don't for get to reinitialize the shell by close and reopen the terminal or simply sourcing the config,</p><div class="language-sh vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">sh</span><pre class="shiki github-dark-dimmed vp-code-dark"><code><span class="line"><span style="color:#6CB6FF;">source</span><span style="color:#ADBAC7;"> </span><span style="color:#96D0FF;">~/.zshrc</span></span></code></pre><pre class="shiki github-light vp-code-light"><code><span class="line"><span style="color:#005CC5;">source</span><span style="color:#24292E;"> </span><span style="color:#032F62;">~/.zshrc</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br></div></div><p>To check whether the proxy script has taken its effect to the current session, don't forget to rerun the same echo command indicated as above. And up until here, the script has been properly installed and operatable as a charm, if your's still does not take any effect, go through the process again and <strong>read</strong> carefully through the documentation.</p><h2 id="_3-to-all-windows-users" tabindex="-1">3: To All Windows Users <a class="header-anchor" href="#_3-to-all-windows-users" aria-label="Permalink to "3: To All Windows Users""></a></h2><p>The documentation above are mainly targeted towards macOS & Linux users, to setup local proxy with Windows machines there is a complete different approach if you are more comfortably working with Powershells and CMD, since I disused windows less and less frequently by the time I decided to upgrade my device to macOS; even if I did use Windows my primary choice of developmental environment is still Linux by the native support of <a href="https://learn.microsoft.com/en-us/windows/wsl/install" target="_blank" rel="noreferrer">WSL</a> with enhanced Ubuntu version in a virtual environment; the following commands are only done from my prior researches, I do not fully guarantee the usability of the commands, please use them at your own risks if any unexpected errors not only including system crashes or other affiliated damages, I do not relate responsibility to any of those presented.</p><p><img src="`+u+`" alt=""></p><p>Simple concluding, abandon proprietary software, fall in the hug of open source; Linux even if most of the users might feel overwhelming when getting started with the system first <code>:)</code>. Alright, enough with off-topic talkings, let's jump right in the process.</p><h3 id="_3-1-cmd" tabindex="-1">3.1: CMD <a class="header-anchor" href="#_3-1-cmd" aria-label="Permalink to "3.1: CMD""></a></h3><div class="language-cmd vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">cmd</span><pre class="shiki github-dark-dimmed vp-code-dark"><code><span class="line"><span style="color:#F47067;">set </span><span style="color:#ADBAC7;">http_proxy</span><span style="color:#F47067;">=</span><span style="color:#ADBAC7;">http://</span><span style="color:#6CB6FF;">127.0.0.1</span><span style="color:#ADBAC7;">:</span><span style="color:#6CB6FF;">7890</span></span>
|
||
<span class="line"><span style="color:#F47067;">set </span><span style="color:#ADBAC7;">https_proxy</span><span style="color:#F47067;">=</span><span style="color:#ADBAC7;">http://</span><span style="color:#6CB6FF;">127.0.0.1</span><span style="color:#ADBAC7;">:</span><span style="color:#6CB6FF;">7890</span></span></code></pre><pre class="shiki github-light vp-code-light"><code><span class="line"><span style="color:#D73A49;">set </span><span style="color:#24292E;">http_proxy</span><span style="color:#D73A49;">=</span><span style="color:#24292E;">http://</span><span style="color:#005CC5;">127.0.0.1</span><span style="color:#24292E;">:</span><span style="color:#005CC5;">7890</span></span>
|
||
<span class="line"><span style="color:#D73A49;">set </span><span style="color:#24292E;">https_proxy</span><span style="color:#D73A49;">=</span><span style="color:#24292E;">http://</span><span style="color:#005CC5;">127.0.0.1</span><span style="color:#24292E;">:</span><span style="color:#005CC5;">7890</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br><span class="line-number">2</span><br></div></div><p>The commands are basically the same to Unix but the major difference is the amend commands in Windows are <code>set</code> instead of <code>export</code>. Once again I haven't personally tested the command, thus only use them as a reference. And whenever you wish to unset the global proxy for the session just simply run the <code>set</code> proxy command again but without any proxy server details.</p><div class="language-cmd vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">cmd</span><pre class="shiki github-dark-dimmed vp-code-dark"><code><span class="line"><span style="color:#F47067;">set </span><span style="color:#ADBAC7;">http_proxy</span><span style="color:#F47067;">=</span></span>
|
||
<span class="line"><span style="color:#F47067;">set </span><span style="color:#ADBAC7;">https_proxy</span><span style="color:#F47067;">=</span></span></code></pre><pre class="shiki github-light vp-code-light"><code><span class="line"><span style="color:#D73A49;">set </span><span style="color:#24292E;">http_proxy</span><span style="color:#D73A49;">=</span></span>
|
||
<span class="line"><span style="color:#D73A49;">set </span><span style="color:#24292E;">https_proxy</span><span style="color:#D73A49;">=</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br><span class="line-number">2</span><br></div></div><h3 id="_3-2-powershell" tabindex="-1">3.2: PowerShell <a class="header-anchor" href="#_3-2-powershell" aria-label="Permalink to "3.2: PowerShell""></a></h3><p>Alike CMD, the string after are exactly the same but the setup prefix command differentiates,</p><div class="language-powershell vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">powershell</span><pre class="shiki github-dark-dimmed vp-code-dark"><code><span class="line"><span style="color:#ADBAC7;">$</span><span style="color:#6CB6FF;">env:</span><span style="color:#ADBAC7;">http_proxy</span><span style="color:#F47067;">=</span><span style="color:#96D0FF;">"http://127.0.0.1:1080"</span></span>
|
||
<span class="line"><span style="color:#ADBAC7;">$</span><span style="color:#6CB6FF;">env:</span><span style="color:#ADBAC7;">https_proxy</span><span style="color:#F47067;">=</span><span style="color:#96D0FF;">"http://127.0.0.1:1080"</span></span></code></pre><pre class="shiki github-light vp-code-light"><code><span class="line"><span style="color:#24292E;">$</span><span style="color:#005CC5;">env:</span><span style="color:#24292E;">http_proxy</span><span style="color:#D73A49;">=</span><span style="color:#032F62;">"http://127.0.0.1:1080"</span></span>
|
||
<span class="line"><span style="color:#24292E;">$</span><span style="color:#005CC5;">env:</span><span style="color:#24292E;">https_proxy</span><span style="color:#D73A49;">=</span><span style="color:#032F62;">"http://127.0.0.1:1080"</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br><span class="line-number">2</span><br></div></div><p>And to revert to the default proxy setting, execute the following command to unset both the http and https proxy.</p><div class="language-powershell vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">powershell</span><pre class="shiki github-dark-dimmed vp-code-dark"><code><span class="line"><span style="color:#ADBAC7;">$</span><span style="color:#6CB6FF;">env:</span><span style="color:#ADBAC7;">http_proxy</span><span style="color:#F47067;">=</span><span style="color:#96D0FF;">""</span></span>
|
||
<span class="line"><span style="color:#ADBAC7;">$</span><span style="color:#6CB6FF;">env:</span><span style="color:#ADBAC7;">https_proxy</span><span style="color:#F47067;">=</span><span style="color:#96D0FF;">""</span></span></code></pre><pre class="shiki github-light vp-code-light"><code><span class="line"><span style="color:#24292E;">$</span><span style="color:#005CC5;">env:</span><span style="color:#24292E;">http_proxy</span><span style="color:#D73A49;">=</span><span style="color:#032F62;">""</span></span>
|
||
<span class="line"><span style="color:#24292E;">$</span><span style="color:#005CC5;">env:</span><span style="color:#24292E;">https_proxy</span><span style="color:#D73A49;">=</span><span style="color:#032F62;">""</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br><span class="line-number">2</span><br></div></div><h2 id="_4-extended-trivia-on-proxy" tabindex="-1">4: Extended Trivia on Proxy <a class="header-anchor" href="#_4-extended-trivia-on-proxy" aria-label="Permalink to "4: Extended Trivia on Proxy""></a></h2><p>Sometimes a proxy server may require an authentication procedure involving passcode for accessing before establishing a secure connection to interact with the server itself. From the partial article above we only discussed on a simple local proxy server setup including a host IP with its forwarded port gateways; but when facing the scenario described for a net connection, we will need a bit more complex method when working in the CLI environment.</p><p>Before we start, quoting from one of the answer from <a href="https://askubuntu.com/questions/583797/how-to-set-a-proxy-for-terminal" target="_blank" rel="noreferrer">AskUbuntu</a>, resolving the misconception on the difference between terminal application and the net utilities falls underly,</p><blockquote><p>Terminal is not net application. Maybe is better to say, in your case, terminal is container for net application like <code>ssh</code>, <code>telnet</code>, <code>lftp</code>, <code>wget</code>, <code>lynx</code> ...</p></blockquote><p>A terminal provides a command-line interface that allows users to send commands and receive responses from network applications, facilitating communication and control over a network connection. It acts as a mediator between the user and the network applications, enabling the user to send instructions and receive information, but not a proxy client.</p><p align="center"><img src="`+m+`" width="200" height="145" align="center"></p><p>Done with the technical talkings, now let's dive into the actual configuration process of the shell. Other than simply inputting a host IP and a port followed, the following formats are the default configuration for a proxy server with HTTP connection protocol, follow the exact same process as described based on your shell type, modify the fields with the following,</p><div class="language-shell vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">shell</span><pre class="shiki github-dark-dimmed vp-code-dark"><code><span class="line"><span style="color:#F47067;">export</span><span style="color:#ADBAC7;"> http_proxy</span><span style="color:#F47067;">=</span><span style="color:#96D0FF;">http://username:password@proxyhost:port/</span></span>
|
||
<span class="line"><span style="color:#F47067;">export</span><span style="color:#ADBAC7;"> ftp_proxy</span><span style="color:#F47067;">=</span><span style="color:#96D0FF;">http://username:password@proxyhost:port/</span></span>
|
||
<span class="line"><span style="color:#F47067;">export</span><span style="color:#ADBAC7;"> telnet_proxy</span><span style="color:#F47067;">=</span><span style="color:#96D0FF;">http://username:password@proxyhost:port/</span></span></code></pre><pre class="shiki github-light vp-code-light"><code><span class="line"><span style="color:#D73A49;">export</span><span style="color:#24292E;"> http_proxy</span><span style="color:#D73A49;">=</span><span style="color:#032F62;">http://username:password@proxyhost:port/</span></span>
|
||
<span class="line"><span style="color:#D73A49;">export</span><span style="color:#24292E;"> ftp_proxy</span><span style="color:#D73A49;">=</span><span style="color:#032F62;">http://username:password@proxyhost:port/</span></span>
|
||
<span class="line"><span style="color:#D73A49;">export</span><span style="color:#24292E;"> telnet_proxy</span><span style="color:#D73A49;">=</span><span style="color:#032F62;">http://username:password@proxyhost:port/</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br></div></div><p>Another approach suggested by the same user whom provided the answer on AskUbuntu for all Ubuntu users, edit the proxy configuration at the root of your machine as follows,</p><div class="language-sh vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">sh</span><pre class="shiki github-dark-dimmed vp-code-dark"><code><span class="line"><span style="color:#F69D50;">sudo</span><span style="color:#ADBAC7;"> </span><span style="color:#6CB6FF;">-H</span><span style="color:#ADBAC7;"> </span><span style="color:#96D0FF;">vim</span><span style="color:#ADBAC7;"> </span><span style="color:#96D0FF;">/etc/profile.d/proxy.sh</span></span></code></pre><pre class="shiki github-light vp-code-light"><code><span class="line"><span style="color:#6F42C1;">sudo</span><span style="color:#24292E;"> </span><span style="color:#005CC5;">-H</span><span style="color:#24292E;"> </span><span style="color:#032F62;">vim</span><span style="color:#24292E;"> </span><span style="color:#032F62;">/etc/profile.d/proxy.sh</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br></div></div><p>And add the exported proxy members aligning the format as above, then save and reinitialize the environment, viola. The patches edited are mainly targeted for incorporating with <code>wget</code>, <code>ftp</code>, <code>lftp</code>, <code>telnet</code> in terminal.</p><p>When working with <code>ssh</code> instance over a proxy, a different approach has to be taken since SSH library does not natively support <code>SOCKS5</code> client, user will have to pass a <code>ProxyCommand</code> option as a workaround to apply proxied connection, below is an instance of <code>socat</code>,</p><div class="language-sh vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">sh</span><pre class="shiki github-dark-dimmed vp-code-dark"><code><span class="line"><span style="color:#F69D50;">ssh</span><span style="color:#ADBAC7;"> </span><span style="color:#6CB6FF;">-o</span><span style="color:#ADBAC7;"> </span><span style="color:#96D0FF;">ProxyCommand='socat - SOCKS4A:myproxy:%h:%p,socksuser=nobody'</span><span style="color:#ADBAC7;"> </span><span style="color:#96D0FF;">user@host</span></span></code></pre><pre class="shiki github-light vp-code-light"><code><span class="line"><span style="color:#6F42C1;">ssh</span><span style="color:#24292E;"> </span><span style="color:#005CC5;">-o</span><span style="color:#24292E;"> </span><span style="color:#032F62;">ProxyCommand='socat - SOCKS4A:myproxy:%h:%p,socksuser=nobody'</span><span style="color:#24292E;"> </span><span style="color:#032F62;">user@host</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br></div></div><p>The <code>proxyCommand</code> option allows user to integrate <code>socat</code> as an intermediary mediator to establish connection above a proxy. Other alternatives like <code>tsocks</code> are as well viable to transparently use <code>SOCKS</code> for <code>TCP</code> traffic, Exemplifying running <code>SOCKS5</code> over <code>socat2</code>,</p><div class="language-bash vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">bash</span><pre class="shiki github-dark-dimmed vp-code-dark"><code><span class="line"><span style="color:#F69D50;">ssh</span><span style="color:#ADBAC7;"> </span><span style="color:#6CB6FF;">-o</span><span style="color:#ADBAC7;"> </span><span style="color:#96D0FF;">ProxyCommand='socat - "SOCKS5:%h:%p|tcp:myproxy:1080"'</span><span style="color:#ADBAC7;"> </span><span style="color:#96D0FF;">user@host</span></span></code></pre><pre class="shiki github-light vp-code-light"><code><span class="line"><span style="color:#6F42C1;">ssh</span><span style="color:#24292E;"> </span><span style="color:#005CC5;">-o</span><span style="color:#24292E;"> </span><span style="color:#032F62;">ProxyCommand='socat - "SOCKS5:%h:%p|tcp:myproxy:1080"'</span><span style="color:#24292E;"> </span><span style="color:#032F62;">user@host</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br></div></div><p>Further, <code>socat2</code> for HTTP Proxy CONNECT method,</p><div class="language-bash vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">bash</span><pre class="shiki github-dark-dimmed vp-code-dark"><code><span class="line"><span style="color:#F69D50;">ssh</span><span style="color:#ADBAC7;"> </span><span style="color:#6CB6FF;">-o</span><span style="color:#ADBAC7;"> </span><span style="color:#96D0FF;">ProxyCommand='socat - "PROXY:%h:%p|tcp:myproxy:80"'</span><span style="color:#ADBAC7;"> </span><span style="color:#96D0FF;">user@host</span></span></code></pre><pre class="shiki github-light vp-code-light"><code><span class="line"><span style="color:#6F42C1;">ssh</span><span style="color:#24292E;"> </span><span style="color:#005CC5;">-o</span><span style="color:#24292E;"> </span><span style="color:#032F62;">ProxyCommand='socat - "PROXY:%h:%p|tcp:myproxy:80"'</span><span style="color:#24292E;"> </span><span style="color:#032F62;">user@host</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br></div></div><div class="tip custom-block"><p class="custom-block-title">Reference</p><ul><li><a href="https://askubuntu.com/questions/583797/how-to-set-a-proxy-for-terminal" target="_blank" rel="noreferrer">https://askubuntu.com/questions/583797/how-to-set-a-proxy-for-terminal</a></li><li><a href="https://zhuanlan.zhihu.com/p/357875811" target="_blank" rel="noreferrer">https://zhuanlan.zhihu.com/p/357875811</a></li><li><a href="https://askubuntu.com/questions/158557/setting-proxy-for-apt-from-terminal" target="_blank" rel="noreferrer">https://askubuntu.com/questions/158557/setting-proxy-for-apt-from-terminal</a> :::</li></ul></div>`,65);function w(F,x,C,A,D,k){const a=o;return l(),p("div",null,[b,r(a,{readTime:"17",words:"2.8k"}),g,e(" while I adopt absolute subjective yet objective perspectives on the individual viewpoints towards the MIIT department of each country those of which applies the internet regulatory services within the national range for avoiding pitfalls on misleading information brought by cross-border influences; meanwhile regardlessly such measures are still facing controversial debates amongst publics that vastly limits the independent freedom rights, though advantages must not be underestimated, still. "),v])}const T=t(f,[["render",w]]);export{q as __pageData,T as default};
|