2
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

WindowsとWSL双方で簡単にGit認証する構成

2
Posted at

目的

メインのOSはWindowsですが、WSL(Windows Subsystem for Linux)も使っていて、両方の環境で git を使っています。GitレポジトリにアクセスするのにOAuth2や2段階認証を設定している場合、Windows側にすでにインストールしているGCM (Git Credential Manager)をWSL側からも参照して認証フローを任せるようにします。

一旦認証が成功したらGCMがトークンを安全に保存し、その後のアクセスでは認証フローがスキップされます。GCMが共有されているのでWindows側とWSL側の両方で保存済みトークンが利用できます。

手順

下図で示すような構成にします。Windows側のgit と GCMはそのままで、WSL側のgit を設定してCドライブ内のGCMを指すようにします。

image.png

GCMがデフォルトの場所に保存されているとして、WSL側(ubuntu のコンソール)から以下を実行します。

git config --global credential.helper "/mnt/c/Program\ Files/Git/mingw64/bin/git-credential-manager.exe"

WSL側でGCMが正しく設定されているかどうかを確認します。

image.png

完了です。

2
2
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
2
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?