Skip to content

Instantly share code, notes, and snippets.

@seangeleno
Forked from wonderbeyond/set-apt-proxy.md
Last active February 10, 2023 20:39
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 seangeleno/dd69601a14ddc990003a44b27a2002a0 to your computer and use it in GitHub Desktop.
Save seangeleno/dd69601a14ddc990003a44b27a2002a0 to your computer and use it in GitHub Desktop.
[ubuntu][socks5][proxy] Set proxy for apt
#!/bin/bash
## TURN OFF socks proxy for aptitude package manager on debian
cat /etc/apt/apt.conf.d/proxy.conf | sed 's/Acquire/\#Acquire/g' | sudo tee /etc/apt/apt.conf.d/proxy.conf

Writing an apt proxy conf file /etc/apt/apt.conf.d/proxy.conf as below.

Acquire::http::Proxy "socks5h://127.0.0.1:1080";
Acquire::https::Proxy "socks5h://127.0.0.1:1080";
Acquire::socks::Proxy "socks5h://127.0.0.1:1080";

ie:

SOCKSPORT=1337

for i in http https socks; do
  echo "Acquire::$i::Proxy \"socks5h://127.0.0.1:$SOCKSPORT\";"
  done | sudo tee /etc/apt/apt.conf.d/proxy.conf
  
  exit 0

And the proxy settings will be applied the next time we run apt.

References: https://www.serverlab.ca/tutorials/linux/administration-linux/how-to-set-the-proxy-for-apt-for-ubuntu-18-04/

#!/bin/bash
# ask user for port number
#read "What port would you like to use for the socks5 connection?"
#define socksport variable or use 1337 as default
# if SOCKSPORT is not defined set it to 1337
SOCKSPORT=1337
for i in http https socks; do
echo "Acquire::$i::Proxy \"socks5h://127.0.0.1:$SOCKSPORT\";"
done | sudo tee /etc/apt/apt.conf.d/proxy.conf
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment