Configure APT Proxy on Debian 10 Buster

0
3010

In this guide guide, we are going to learn how to configure APT Proxy on Debian 10 Buster. If you are be running a Debian 10 system behind a proxy server, chances are you have unsuccessfully tried to install packages. Learn how to configure APT package manager to use HTTP or HTTPS proxy server while pulling packages from the repositories.

Configure APT Proxy on Debian 10 Buster

To configure APT proxy on Debian 10 Buster, you need to have the IP address and the port of the proxy server as well as the authentication username and password if at all your proxy server supports authentication. APT can be temporarily or permanently configured to use proxy.

Temporary APT Proxy Configuration

Temporary APT proxy configuration involves creating proxy environment variables which can either be http_proxy or https_proxy as shown below;

In my environment, 192.168.43.1 is the proxy server IP and 3128 is the proxy server port.

For HTTP proxy, simply run the command below to create an http_proxy environment variable which defines your proxy server and the port.

export http_proxy='http://192.168.43.1:3128'

For HTTPS proxy;

export https_proxy='https://192.168.43.1:3128'

If your proxy supports authentication and requires a username/password for login, simply use;

For HTTP(S) proxy;

export http_proxy='http://USERNAME:PASSWORD@192.168.43.1:3128'
export https_proxy='https://USERNAME:PASSWORD@192.168.43.1:3128'

You can as well prefix apt command with proxy settings as shown below;

sudo 'http_proxy=http://192.168.43.100:3128' apt update

or

sudo 'http_proxy=http://Username:[email protected]:3128' apt update

Permanent APT Proxy Configuration

You can permanently configure APT proxy on APT configuration file. For example, you can create a proxy configuration file under the /apt/apt.conf.d directory as shown below;

vim /etc/apt/apt.conf.d/02proxy

For HTTP Proxy;

Acquire::http::Proxy "http://PROXYSERVERIP:PROXYPORT";

For HTTPS;

Acquire::https::Proxy "https://PROXYSERVERIP:PROXYPORT";

To configure for both HTTP and HTTPS;

Acquire::http::Proxy "http://PROXYSERVERIP:PROXYPORT";
Acquire::https::Proxy "https://PROXYSERVERIP:PROXYPORT";

Or simply;

Acquire {
  HTTP::proxy "http://PROXYSERVERIP:PROXYPORT";
  HTTPS::proxy "http://PROXYSERVERIP:PROXYPORT";
}

If your proxy supports authentication, replace;

http://PROXYSERVERIP:PROXYPORT

with;

http://USERNAME:[email protected]:PROXYPORT

Such that your lines look like;

Acquire::http::proxy "http://USERNAME:[email protected]:PROXYPORT";
Acquire::https::proxy "https://USERNAME:[email protected]:PROXYPORT";

You can also configure system wide proxy that applies to any user that logs into the system on /etc/profile.d by setting the http_proxy and https_proxy variables. For example, create a file, /etc/profile.d/proxy.sh with the following environment variables set.

vim /etc/profile.d/proxy.sh
export http_proxy='http://USERNAME:[email protected]:3128'
export https_proxy='https://USERNAME:[email protected]:3128'

source the proxy configuration file to reload environment variables.

source /etc/profile.d/proxy.sh

If you are using bash shell, then to set the proxy that applies for a single user, you can edit the $HOME/.bashrc file and add the lines;

vim $HOME/.bashrc
export http_proxy='http://USERNAME:[email protected]:3128'
export https_proxy='https://USERNAME:[email protected]:3128'

source the $HOME/.bashrc file:

source $HOME/.bashrc

Now, if you try to run apt command, you will note that it tries to connect to proxy server. If connection is successful, you APT will run with no issues.

apt update
0% [Connecting to 192.168.43.1 (192.168.43.1)]...

That is all on how to configure APT Proxy on Debian 10 Buster. Enjoy

Related Tutorials;

Install Grafana Plugins Behind a Proxy server

How to Set System Wide Proxy in Ubuntu 18.04

Setup Squid Proxy Authentication on Ubuntu 18.04/Fedora 29/28/CentOS 7

How to Install and Configure Squid Proxy on Fedora 29/Fedora 28/CentOS 7

LEAVE A REPLY

Please enter your comment!
Please enter your name here