Skip to content

Instantly share code, notes, and snippets.

@h-east
Last active November 5, 2018 02:05
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 h-east/299c950f2b909cb6f48bc69e735c778e to your computer and use it in GitHub Desktop.
Save h-east/299c950f2b909cb6f48bc69e735c778e to your computer and use it in GitHub Desktop.
GitHubで2要素認証を設定しているユーザーが gitにhttpsでアクセスする時に認証情報入力を省く方法

コメントに書く。

@h-east
Copy link
Author

h-east commented Nov 1, 2018

ふへぇ。やっと職場のUbuntu 18.04からgit push出来るようになった。
sshダメだったのでhttpsで試したけど、2要素認証なのに普通にパスワード入力して「できね~」となっていた。

パスワード替わりのアクセストークンは、GitHub→Settings→Developer settings→Personal access tokens で "Generate new token" で作成。Token descriptionを適当に入力、Select scopes は repo, gist, user にチェックを入れた。(多分 repo だけでいいかも)

あと、git-credential-libsecretで認証情報を保存させるのがこれまた大変だった。

  1. ビルド用のパッケージ入れて
    $ sudo apt-get install libsecret-1-0 libsecret-1-dev

  2. ビルドして
    $ cd /usr/share/doc/git/contrib/credential/libsecret/
    $ sudo make

  3. gitに登録して
    $ git config --global credential.helper /usr/share/doc/git/contrib/credential/libsecret/git-credential-libsecret
    $ git config --global credential.https://github.com.username ユーザー名

これで、git pushしたらエラーが出た。
** Message: 14:54:45.116: Remote error from secret service: org.freedesktop.Secret.Error.IsLocked: Cannot create an item in a locked collection
** (process:8601): CRITICAL **: 14:54:45.116: store failed: Cannot create an item in a locked collection

ググってもあまり情報がなかった。けどなんとか分かった。
GUIでseahorse を起動して、「+」を押して "Password Keyring" で Continue。
適当に名前を付けて、パスワード2回入れて OK を押す。
GUIでログインしておかないとこのエラーが出る。

これで、2回目のgit pushからパスワード入力が不要になる。

めでたし。めでたし。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment