Life behind proxy

This topic is a cheat sheet for people who have to work behind proxy.

There are some placeholders that will be used later. It is obvious to guess what they mean, but I give some details to avoid misunderstanding.

PROXY_URL - proxy url, that all your traffic goes through.
PROXY_PORT - proxy port.

PROXY_USER - your login for a proxy.
PROXY_PASS - your password.

apt (package manager of debian-based distribution)

cat /etc/apt/apt.conf.d/proxy.conf

Acquire::https::Verify-Peer "false";
Acquire::https::Verify-Host "false";

Acquire {
  AllowUnauthenticated "true";
  HTTP::proxy "http://<proxy_user>:<proxy_pass>@<PROXY_URL>:<PROXY_PORT>/";
  HTTPS::proxy "http://<proxy_user>:<proxy_pass>@<PROXY_URL>:<PROXY_PORT>/";
}

gradle (dependency manager and build automation tool)

cat gradle.properties
systemProp.http.proxyHost=<PROXY_URL>
systemProp.http.proxyPort=<PROXY_PORT>
systemProp.http.proxyUser=<proxy_user>
systemProp.http.proxyPassword=<PROXY_USER>

systemProp.https.proxyHost=<PROXY_URL>
systemProp.https.proxyPort=<PROXY_PORT>
systemProp.https.proxyUser=<PROXY_USER>
systemProp.https.proxyPassword=<PROXY_PASS>

maven (dependency manager for java projects)

cat ~/.m2/settings.xml

Take your notice, file below involves environment variables. If you are not going to use them, just put ordinal values instead of ${env.*}.

<settings>
  <proxies>
   <proxy>
      <id>http-proxy</id>
      <active>true</active>
      <protocol>http</protocol>
      <host>${env.PROXY_URL}</host>
      <port>${env.PROXY_PORT}</port>
      <username>${env.PROXY_USER}</username>
      <password>${env.PROXY_PASS}</password>
      <nonProxyHosts>localhost|my-domain</nonProxyHosts>
    </proxy>
    <proxy>
      <id>https-proxy</id>
      <active>true</active>
      <protocol>https</protocol>
     <host>${env.PROXY_URL}</host>
      <port>${env.PROXY_PORT}</port>
      <username>${env.PROXY_USER}</username>
      <password>${env.PROXY_PASS}</password>
      <nonProxyHosts>localhost|my-domain</nonProxyHosts>
    </proxy>
  </proxies>

  ...
</settings>

sbt (build tool for scala projects, preemptively)

export SBT_OPTS=" \
-Dhttp.proxySet=true \
-Dhttp.proxyHost=${PROXY_URL} \
-Dhttp.proxyPort=${PROXY_PORT} \
-Dhttp.proxyUser=${PROXY_USER} \
-Dhttp.proxyPassword=${PROXY_PASS} \
-Dhttp.nonProxyHosts=my-domain \
-Dhttps.proxySet=true \
-Dhttps.proxyHost=${PROXY_URL} \
-Dhttps.proxyPort=${PROXY_PORT} \
-Dhttps.proxyUser=${PROXY_USER} \
-Dhttps.proxyPassword=${PROXY_PASS} \
-Dhttps.nonProxyHosts=my-domain \

git (you, definitely, know what it is) 🙂

cat ~/.gitconfig
[http]
    proxy = http://<PROXY_USER>:<PROXY_PASS>@<PROXY_URL>:<PROXY_PORT>
    sslVerify = false
[https]
    proxy = http://<PROXY_USER>:<PROXY_PASS>@<PROXY_URL>:<PROXY_PORT>
    sslVerify = false
[http "local-git-repo"]
    proxy = ""
    sslVerify = false
[https "local-git-repo"]
    proxy = ""
    sslVerify = false

curl (tool for downloading some stuff from the internet)

export http_proxy=http://<PROXY_USER>:<PROXY_PASS>@<PROXY_URL>:<PROXY_PORT>
export https_proxy=http://<PROXY_USER>:<PROXY_PASS>@<PROXY_URL>:<PROXY_PORT>

pip (dependency manager for python projects)

Pip uses environment variables that curl uses, but there is another way to work with it.
The program has a flag called --proxy:

pip install --proxy http://<PROXY_USER>:<PROXY_PASS>@<PROXY_URL>:<PROXY_PORT> ...

You may have some troubles because of wrong SSL certificates. To say PIP to ignore this type of errors, you can also pass the param with all used repositories: --trusted-host=pipy.org --trusted-host=files.pythonhosted.org ....

npm package manager for javascript projects.

To work with npm behind proxy, you should type only 3 commands:

npm config set strict-ssl false
npm config set https-proxy http://<PROXY_USER>:<PROXY_PASS>@<PROXY_URL>:<PROXY_PORT>
npm config set http-proxy http://<PROXY_USER>:<PROXY_PASS>@<PROXY_URL>:<PROXY_PORT>