Last active
April 26, 2023 07:08
-
-
Save siddhpant/0c5dd3d5bf4762b0d4c4bb2ac75026f7 to your computer and use it in GitHub Desktop.
Some helpers for using connection via proxy in bash, when you don't want to save your credentials in standard locations (for eg. in shared PCs).
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
myproxy() | |
{ | |
read -p "Username: " USER | |
read -s -p "Password: " PW | |
echo | |
hostname="proxy.example.com" | |
port="3128" | |
PROXY="$(jq -rn --arg x $USER '$x|@uri'):$(jq -rn --arg x $PW '$x|@uri')@$hostname:$port" | |
export http_proxy="http://$PROXY" | |
export https_proxy="https://$PROXY" | |
export ftp_proxy="ftp://$PROXY" | |
export Proxy="$http_proxy" | |
export HTTP_PROXY="$http_proxy" | |
export HTTPS_PROXY="$https_proxy" | |
export FTP_PROXY="$ftp_proxy" | |
unset USER | |
unset PROXY | |
unset PW | |
# For checking if we connect properly. | |
curl https://raw.githubusercontent.com/siddhpant/1-byte-file/main/1_byte_file | |
echo | |
} | |
alias proxy-apt='sudo -E apt -o Acquire::http::proxy="$http_proxy" -o Acquire::https::proxy="$https_proxy" -o Acquire::ftp::proxy="$ftp_proxy"' | |
alias proxy-pip='python3.11 -m pip --proxy "$http_proxy"' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Run
myproxy
every time you open the terminal.