Skip to content

Instantly share code, notes, and snippets.

@siddhpant
Last active April 26, 2023 07:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save siddhpant/0c5dd3d5bf4762b0d4c4bb2ac75026f7 to your computer and use it in GitHub Desktop.
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).
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"'
@siddhpant
Copy link
Author

Run myproxy every time you open the terminal.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment