List of Credential - text.Baldanders.info
tag:text.Baldanders.info,2019-04-08:/tags
2019-04-08T00:12:49+09:00
帰ってきた「しっぽのさきっちょ」
https://text.baldanders.info/images/avatar.jpg
https://text.baldanders.info/images/avatar.jpg
PPA から Git をインストールする
tag:text.Baldanders.info,2019-04-08:/remark/2019/04/install-git-from-ppa/
2019-04-07T15:12:49+00:00
2020-06-06T11:40:22+00:00
Git に関しては PPA (Personal Package Archive) で最新版のビルドを提供されている方がいるらしい。ありがたや。
Spiegel
https://baldanders.info/profile/
<p><a href="https://text.baldanders.info/remark/2019/04/move-gpg-keyring/" title="Windows 環境で作った GnuPG の鍵束を Ubuntu に移行する">前回</a>で <a href="http://www.openssh.com/" title="OpenSSH">OpenSSH</a> と <a href="https://gnupg.org/" title="The GNU Privacy Guard">GnuPG</a> を連携させたのでようやく <a href="https://git-scm.com/">git</a> で遊べるようになった。</p>
<p>しかし,実際にコマンドを叩いてみたら</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-text" data-lang="text"><span class="line"><span class="cl">$ git version
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl">Command 'git' not found, but can be installed with:
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl">sudo apt install git
</span></span></code></pre></div><p>またかよ。
嫌な予感しかしない。</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-text" data-lang="text"><span class="line"><span class="cl">$ sudo apt show git
</span></span><span class="line"><span class="cl">Package: git
</span></span><span class="line"><span class="cl">Version: 1:2.19.1-1ubuntu1.1
</span></span><span class="line"><span class="cl">Priority: optional
</span></span><span class="line"><span class="cl">Section: vcs
</span></span><span class="line"><span class="cl">Origin: Ubuntu
</span></span><span class="line"><span class="cl">...
</span></span></code></pre></div><p>やっぱり。
2.21.0 が出たのってだいぶ前だよな。</p>
<p>いろいろ調べてみたら <a href="https://git-scm.com/">git</a> に関しては <a href="https://launchpad.net/ubuntu/+ppas">PPA (Personal Package Archive)</a> で最新版のビルドを提供されている方がいるらしい。
ありがたや。</p>
<ul>
<li><a href="https://launchpad.net/~git-core/+archive/ubuntu/ppa">Git stable releases : “Ubuntu Git Maintainers” team</a></li>
</ul>
<p>何故か <code>add-apt-repository</code> は既に入ってるぽかったので,まずはリポジトリを導入しよう。</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-text" data-lang="text"><span class="line"><span class="cl">$ sudo add-apt-repository ppa:git-core/ppa
</span></span><span class="line"><span class="cl"> The most current stable version of Git for Ubuntu.
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl">For release candidates, go to https://launchpad.net/~git-core/+archive/candidate .
</span></span><span class="line"><span class="cl"> 詳しい情報: https://launchpad.net/~git-core/+archive/ubuntu/ppa
</span></span><span class="line"><span class="cl">[ENTER] を押すと続行します。Ctrl-c で追加をキャンセルできます。
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl">ヒット:1 http://jp.archive.ubuntu.com/ubuntu cosmic InRelease
</span></span><span class="line"><span class="cl">取得:2 http://jp.archive.ubuntu.com/ubuntu cosmic-updates InRelease [88.7 kB]
</span></span><span class="line"><span class="cl">ヒット:3 http://archive.ubuntulinux.jp/ubuntu cosmic InRelease
</span></span><span class="line"><span class="cl">取得:4 http://jp.archive.ubuntu.com/ubuntu cosmic-backports InRelease [74.6 kB]
</span></span><span class="line"><span class="cl">ヒット:5 http://archive.ubuntulinux.jp/ubuntu-ja-non-free cosmic InRelease
</span></span><span class="line"><span class="cl">取得:6 http://security.ubuntu.com/ubuntu cosmic-security InRelease [88.7 kB]
</span></span><span class="line"><span class="cl">取得:7 http://ppa.launchpad.net/git-core/ppa/ubuntu cosmic InRelease [20.7 kB]
</span></span><span class="line"><span class="cl">取得:8 http://ppa.launchpad.net/git-core/ppa/ubuntu cosmic/main i386 Packages [3,032 B]
</span></span><span class="line"><span class="cl">取得:9 http://ppa.launchpad.net/git-core/ppa/ubuntu cosmic/main amd64 Packages [3,032 B]
</span></span><span class="line"><span class="cl">取得:10 http://ppa.launchpad.net/git-core/ppa/ubuntu cosmic/main Translation-en [2,248 B]
</span></span><span class="line"><span class="cl">281 kB を 3秒 で取得しました (81.9 kB/s)
</span></span><span class="line"><span class="cl">パッケージリストを読み込んでいます... 完了
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl">$ sudo apt update
</span></span><span class="line"><span class="cl">ヒット:1 http://archive.ubuntulinux.jp/ubuntu cosmic InRelease
</span></span><span class="line"><span class="cl">ヒット:2 http://jp.archive.ubuntu.com/ubuntu cosmic InRelease
</span></span><span class="line"><span class="cl">ヒット:3 http://archive.ubuntulinux.jp/ubuntu-ja-non-free cosmic InRelease
</span></span><span class="line"><span class="cl">取得:4 http://jp.archive.ubuntu.com/ubuntu cosmic-updates InRelease [88.7 kB]
</span></span><span class="line"><span class="cl">取得:5 http://jp.archive.ubuntu.com/ubuntu cosmic-backports InRelease [74.6 kB]
</span></span><span class="line"><span class="cl">取得:6 http://security.ubuntu.com/ubuntu cosmic-security InRelease [88.7 kB]
</span></span><span class="line"><span class="cl">ヒット:7 http://ppa.launchpad.net/git-core/ppa/ubuntu cosmic InRelease
</span></span><span class="line"><span class="cl">252 kB を 2秒 で取得しました (155 kB/s)
</span></span><span class="line"><span class="cl">パッケージリストを読み込んでいます... 完了
</span></span><span class="line"><span class="cl">依存関係ツリーを作成しています
</span></span><span class="line"><span class="cl">状態情報を読み取っています... 完了
</span></span><span class="line"><span class="cl">パッケージはすべて最新です。
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl">$ sudo apt upgrade
</span></span><span class="line"><span class="cl">パッケージリストを読み込んでいます... 完了
</span></span><span class="line"><span class="cl">依存関係ツリーを作成しています
</span></span><span class="line"><span class="cl">状態情報を読み取っています... 完了
</span></span><span class="line"><span class="cl">アップグレードパッケージを検出しています... 完了
</span></span><span class="line"><span class="cl">アップグレード: 0 個、新規インストール: 0 個、削除: 0 個、保留: 0 個。
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl">$ sudo apt show git
</span></span><span class="line"><span class="cl">Package: git
</span></span><span class="line"><span class="cl">Version: 1:2.21.0-0ppa1~ubuntu18.10.1
</span></span><span class="line"><span class="cl">Priority: optional
</span></span><span class="line"><span class="cl">Section: vcs
</span></span></code></pre></div><p>よし。
最新版が入ってるな。
インストールっと。</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-text" data-lang="text"><span class="line"><span class="cl">$ sudo apt install git
</span></span></code></pre></div><p>これでインストール完了。
動作確認してみる。</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-text" data-lang="text"><span class="line"><span class="cl">$ git version
</span></span><span class="line"><span class="cl">git version 2.21.0
</span></span></code></pre></div><p>よしよし。
おっと,初期設定しないと。</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-text" data-lang="text"><span class="line"><span class="cl">$ git config --global user.name "Alice"
</span></span><span class="line"><span class="cl">$ git config --global user.email "alice@example.com"
</span></span><span class="line"><span class="cl">$ git config --global user.signingkey 697CDD8A
</span></span><span class="line"><span class="cl">$ git config --global commit.gpgsign true
</span></span></code></pre></div><h2>SSH 経由で git clone する</h2>
<p>まずは適当なリポジトリを SSH 経由で git clone してみる。</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-text" data-lang="text"><span class="line"><span class="cl">$ git clone git@github.com:spiegel-im-spiegel/gocli.git github.com/spiegel-im-spiegel/gocli
</span></span><span class="line"><span class="cl">Cloning into 'github.com/spiegel-im-spiegel/gocli'...
</span></span><span class="line"><span class="cl">The authenticity of host 'github.com (192.30.255.112)' can't be established.
</span></span><span class="line"><span class="cl">RSA key fingerprint is SHA256:xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.
</span></span><span class="line"><span class="cl">Are you sure you want to continue connecting (yes/no)? yes
</span></span><span class="line"><span class="cl">Warning: Permanently added 'github.com,192.30.255.112' (RSA) to the list of known hosts.
</span></span><span class="line"><span class="cl">remote: Enumerating objects: 71, done.
</span></span><span class="line"><span class="cl">remote: Counting objects: 100% (71/71), done.
</span></span><span class="line"><span class="cl">remote: Compressing objects: 100% (52/52), done.
</span></span><span class="line"><span class="cl">remote: Total 246 (delta 31), reused 53 (delta 16), pack-reused 175
</span></span><span class="line"><span class="cl">Receiving objects: 100% (246/246), 53.99 KiB | 431.00 KiB/s, done.
</span></span><span class="line"><span class="cl">Resolving deltas: 100% (107/107), done.
</span></span></code></pre></div><p><a href="https://text.baldanders.info/remark/2019/04/move-gpg-keyring/" title="Windows 環境で作った GnuPG の鍵束を Ubuntu に移行する">前回</a>で <a href="http://www.openssh.com/" title="OpenSSH">OpenSSH</a> と <a href="https://gnupg.org/" title="The GNU Privacy Guard">GnuPG</a> を連携させたので認証時に Pinentry が起動する。</p>
<figure style='margin:0 auto;text-align:center;'><a href="../move-gpg-keyring/ssh-login.png"><img src="../move-gpg-keyring/ssh-login.png" srcset="../move-gpg-keyring/ssh-login.png 500w" sizes="(min-width:600px) 500px, 80vw" alt="" loading="lazy"></a></figure>
<p>よーし,うむうむ,よーし。</p>
<h2>git-credential による認証管理</h2>
<p>SSH 経由でリポジトリにアクセスする場合はこれでいいのだが HTTPS 経由でアクセスする場合はアクセスするたびに毎回パスワードを訊かれるため鬱陶しい。
この場合は git-credential による認証管理を行うのがいいようだ。</p>
<p><a href="https://www.ubuntu.com/" title="The leading operating system for PCs, IoT devices, servers and the cloud | Ubuntu">Ubuntu</a> では gnome-keyring を使った認証管理が使える。</p>
<ul>
<li><a href="https://github.com/shugo/git-credential-gnomekeyring">shugo/git-credential-gnomekeyring: A git credential helper for GNOME keyring</a></li>
</ul>
<p>これによると</p>
<figure lang="en">
<blockquote>
<q>There is a git package that includes all of contrib sources in /usr/share/doc/git/contrib/. Users who want to use git-credential-gnomekeyring should copy source from /usr/share/doc/git/contrib/credential/gnome-keyring to their working directory, then users can make and install it.</q>
</blockquote>
<figcaption><div>via <q><a href="https://github.com/shugo/git-credential-gnomekeyring">shugo/git-credential-gnomekeyring</a></q></div></figcaption>
</figure>
<p>ということらしい。
さっそくやってみよう。</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-text" data-lang="text"><span class="line"><span class="cl">$ cp -r /usr/share/doc/git/contrib/credential/gnome-keyring ~/work
</span></span><span class="line"><span class="cl">$ cd ~/work/gnome-keyring
</span></span><span class="line"><span class="cl">$ make
</span></span><span class="line"><span class="cl">gcc -c -g -O2 -Wall -o git-credential-gnome-keyring.o git-credential-gnome-keyring.c
</span></span><span class="line"><span class="cl">git-credential-gnome-keyring.c:28:10: fatal error: glib.h: そのようなファイルやディレクトリはありません
</span></span></code></pre></div><p>まじすか。
まぁ,入れればいいか。</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-text" data-lang="text"><span class="line"><span class="cl">$ sudo apt install libglib2.0-dev
</span></span></code></pre></div><p>では再開。</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-text" data-lang="text"><span class="line"><span class="cl">$ make
</span></span><span class="line"><span class="cl">gcc -c -g -O2 -Wall -I/usr/include/glib-2.0 -I/usr/lib/x86_64-linux-gnu/glib-2.0/include -o git-credential-gnome-keyring.o git-credential-gnome-keyring.c
</span></span><span class="line"><span class="cl">git-credential-gnome-keyring.c:29:10: fatal error: gnome-keyring.h: そのようなファイルやディレクトリはありません
</span></span></code></pre></div><p>ええい。
これも入れればいいのね。</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-text" data-lang="text"><span class="line"><span class="cl">$ sudo apt install libgnome-keyring-dev
</span></span></code></pre></div><div class="highlight"><pre tabindex="0" class="chroma"><code class="language-text" data-lang="text"><span class="line"><span class="cl">$ make
</span></span><span class="line"><span class="cl">gcc -g -O2 -Wall -I/usr/include/gnome-keyring-1 -I/usr/include/glib-2.0 -I/usr/lib/x86_64-linux-gnu/glib-2.0/include -o git-credential-gnome-keyring.o -c git-credential-gnome-keyring.c
</span></span></code></pre></div><p>ワーニングいっぱい出たけどようやく通ったよ。
これで作成された <code>git-credential-gnome-keyring</code> をパスの通ったディレクトリに入れれば完了。
<a href="https://git-scm.com/">git</a> 側が認識しているか確認してみよう。</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-text" data-lang="text"><span class="line"><span class="cl">$ git help -a | grep credential-
</span></span><span class="line"><span class="cl"> credential-cache Helper to temporarily store passwords in memory
</span></span><span class="line"><span class="cl"> credential-store Helper to store credentials on disk
</span></span><span class="line"><span class="cl"> credential-gnome-keyring
</span></span></code></pre></div><p>よしよし。
認識しているな。</p>
<p>これで <a href="https://git-scm.com/">git</a> 設定に以下を加えれば完了となる。</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-text" data-lang="text"><span class="line"><span class="cl">$ git config --global credential.helper gnome-keyring
</span></span></code></pre></div><p>適当なリポジトリで確かめてみよう。</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-text" data-lang="text"><span class="line"><span class="cl">$ git clone https://github.com/spiegel-im-spiegel/private-repos.git aaa
</span></span><span class="line"><span class="cl">Cloning into 'aaa'...
</span></span><span class="line"><span class="cl">Username for 'https://github.com': alice@example.com
</span></span><span class="line"><span class="cl">Password for 'https://alice@example.com@github.com':
</span></span><span class="line"><span class="cl">remote: Enumerating objects: 51, done.
</span></span><span class="line"><span class="cl">remote: Counting objects: 100% (51/51), done.
</span></span><span class="line"><span class="cl">remote: Compressing objects: 100% (41/41), done.
</span></span><span class="line"><span class="cl">remote: Total 51 (delta 8), reused 47 (delta 8), pack-reused 0
</span></span><span class="line"><span class="cl">Unpacking objects: 100% (51/51), done.
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl">$ git clone https://github.com/spiegel-im-spiegel/private-repos.git bbb
</span></span><span class="line"><span class="cl">Cloning into 'bbb'...
</span></span><span class="line"><span class="cl">remote: Enumerating objects: 51, done.
</span></span><span class="line"><span class="cl">remote: Counting objects: 100% (51/51), done.
</span></span><span class="line"><span class="cl">remote: Compressing objects: 100% (41/41), done.
</span></span><span class="line"><span class="cl">remote: Total 51 (delta 8), reused 47 (delta 8), pack-reused 0
</span></span><span class="line"><span class="cl">Unpacking objects: 100% (51/51), done.
</span></span></code></pre></div><p>よし。
2回目からは訊いてこないな。</p>
<p>ちなみにこのときのパスワードは Web ページにサインインするときのパスワードじゃなくて,設定画面で振り出した personal access token を使うのでご注意を(つか,私がすっかり忘れててハマったのだが<code>w</code>)。</p>
<h3>【追記】 Libsecret を使う</h3>
<p>gnome-keyring の代わりに libsecret を使う方法もあるようだ。</p>
<ul>
<li><a href="https://hawksnowlog.blogspot.com/2018/10/try-git-credential.html">hawksnowlog: git credential を使おう</a></li>
<li><a href="https://wiki.archlinux.org/index.php/GNOME/Keyring">GNOME/Keyring - ArchWiki</a></li>
</ul>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-text" data-lang="text"><span class="line"><span class="cl">$ sudo apt show libsecret-1-dev
</span></span><span class="line"><span class="cl">Package: libsecret-1-dev
</span></span><span class="line"><span class="cl">Version: 0.18.8-1
</span></span><span class="line"><span class="cl">Priority: optional
</span></span><span class="line"><span class="cl">Section: libdevel
</span></span><span class="line"><span class="cl">Source: libsecret
</span></span><span class="line"><span class="cl">Origin: Ubuntu
</span></span><span class="line"><span class="cl">...
</span></span></code></pre></div><p>既定では入ってないっぽいのでインストールする。</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-text" data-lang="text"><span class="line"><span class="cl">$ sudo apt install libsecret-1-dev
</span></span></code></pre></div><p>以降は nome-keyring のときと同じ</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-text" data-lang="text"><span class="line"><span class="cl">$ cp -r /usr/share/doc/git/contrib/credential/libsecret ~/work
</span></span><span class="line"><span class="cl">$ cd ~/work/libsecret
</span></span><span class="line"><span class="cl">$ make
</span></span><span class="line"><span class="cl">gcc -g -O2 -Wall -pthread -I/usr/include/libsecret-1 -I/usr/include/libmount -I/usr/include/blkid -I/usr/include/uuid -I/usr/include/glib-2.0 -I/usr/lib/x86_64-linux-gnu/glib-2.0/include -o git-credential-libsecret.o -c git-credential-libsecret.c
</span></span><span class="line"><span class="cl">gcc -o git-credential-libsecret git-credential-libsecret.o -lsecret-1 -lgio-2.0 -lgobject-2.0 -lglib-2.0
</span></span></code></pre></div><p>おおっ。
ワーニングが出ない。
こっちのほうがいいかな。</p>
<p>ビルドした git-credential-libsecret をパスの通ったディレクトリに入れれば完了。
<a href="https://git-scm.com/">Git</a> 側が認識しているか確認してみよう。</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-text" data-lang="text"><span class="line"><span class="cl">$ git help -a | grep credential-
</span></span><span class="line"><span class="cl"> credential-cache Helper to temporarily store passwords in memory
</span></span><span class="line"><span class="cl"> credential-store Helper to store credentials on disk
</span></span><span class="line"><span class="cl"> credential-libsecret
</span></span></code></pre></div><p>あとは <a href="https://git-scm.com/">git</a> の設定に組み込めば終了。</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-text" data-lang="text"><span class="line"><span class="cl">$ git config --global credential.helper libsecret
</span></span></code></pre></div><h2>ブックマーク</h2>
<ul>
<li>
<p><a href="https://allabout.co.jp/gm/gc/438675/">UbuntuのPPAて何? [Linuxの使い方] All About</a></p>
</li>
<li>
<p><a href="http://spangled-shalalala.hatenablog.com/entry/2017/09/05/060106">ubuntuのapt-getで最新版のgitをインストールする方法 - spangled shalalala blog</a></p>
</li>
<li>
<p><a href="https://git-scm.com/book/ja/v1/%E4%BD%BF%E3%81%84%E5%A7%8B%E3%82%81%E3%82%8B-Git%E3%81%AE%E3%82%A4%E3%83%B3%E3%82%B9%E3%83%88%E3%83%BC%E3%83%AB">Git - Gitのインストール</a></p>
</li>
<li>
<p><a href="https://text.baldanders.info/openpgp/git-commit-with-openpgp-signature/">Git Commit で OpenPGP 署名を行う</a></p>
</li>
</ul>