LoginSignup
77
83

More than 3 years have passed since last update.

UbuntuのProxy設定備忘録

Last updated at Posted at 2019-12-23

Ubuntuのインストール後、プロキシ環境下で使用するために設定すること一覧
(aptを除いてユーザー毎の設定となっています)

環境設定

まずプロキシ設定の調べ方

printenv http_proxy https_proxy

もし何も出なかった場合~/.bashrcに設定を追記するため、以下を実行

echo -e "\n## proxy setting"  >> ~/.bashrc
echo 'export http_proxy="http://proxy_server:port/"' >> ~/.bashrc
echo 'export https_proxy=$http_proxy' >> ~/.bashrc

aptの設定

apt.confファイルにProxy設定を追加する
シェルにて以下を実行

sudo nano /etc/apt/apt.conf

これにより開いたapt.confファイルに以下を記述し、保存(保存はCtrl+O、終了はCtrl+X)

/etc/apt/apt.conf
Acquire::http::Proxy "http://proxy_server:port";
Acquire::https::Proxy "http://proxy_server:port";

gitの設定

git用のProxy設定

httpsを使う場合

git config --global http.proxy http://proxy_server:port
git config --global https.proxy http://proxy_server:port

sshを使う場合

~/.ssh/configにて以下のような設定をする
鍵の生成等は以下などを参考に設定する
GitHubでssh接続する手順~公開鍵・秘密鍵の生成から~

~/.ssh/config
Host github
  User git
  HostName ssh.github.com
  IdentityFile ~/.ssh/id_rsa
  ProxyCommand nc -X connect -x proxy_server:port %h %p

接続テスト

ssh -T github

Dockerの設定

sudo systemctl edit dockerを実行し、以下のように環境変数の設定を行う

[Service]
Environment = 'http_proxy=http://proxy_server:port' 'https_proxy=http://proxy_server:port'

次に、クライアントの設定のため、~/.docker/config.jsonファイルで以下を記述する

{
  "proxies": {
    "default": {
      "httpProxy": "http://proxy_server:port",
      "httpsProxy": "http://proxy_server:port"
    }
  }
}

参考: プロキシのある環境でDockerを動かす方法

wgetの設定

~/.wgetrcファイルで以下を記述

~/.wgetrc
http_proxy=http://proxy_server:port/
https_proxy=http://proxy_server:port/

add-apt-repositoryでのプロキシの適用

sudoにて-Eオプションを用いることで環境変数を引き継ぐ
参考 【Proxyの外に出れない僕達のために】Proxy 環境下で sudo add-apt-repository する方法【と、sudoとhttp_proxyのなんやかんや】
以下gitの例

sudo -E add-apt-repository ppa:git-core/ppa

apt-keyでのプロキシ適用

cuda toolkit等のインストールではapt-keyを用いることがある
その際、ネットワークエラーが出ることがあるので、以下の様に--keyserver-optionを追加してプロキシ設定をする必要がある

sudo apt-key adv --keyserver-option http-proxy=http://proxy_server:port

オプションの順序として、--keyserver-optionがオプションの先頭に来る必要があることに注意

77
83
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
77
83