LoginSignup
0
2

More than 3 years have passed since last update.

ディレクトリ毎にgitの鍵ファイルを使い分ける

Posted at

gitのremote接続用の鍵を使い分けたい

本当はgithubのアカウントは1つだけで管理したいのだけど、仕事とプライベートで2つのgithubアカウントがある場合などは鍵ファイルも2つになってしまう。だけどPCは1台で作業したい時がある。
しかし、githubには2つのアカウントに同じ鍵は登録できない。でもhttpsとかにして毎回ユーザー名とかパスワード入力するのは面倒なので何とかしたい。

 結論

普段は個人用のid_rsaの鍵ファイルを利用しているか、仕事用の鍵をカレントディレクトリのみに適用させたい場合はgit config --local で以下の様にしていできる。

$ git config --local user.name "仕事アカウント名"
$ git config --local user.email "仕事@メールアドレス"
$ git config --local core.sshCommand "ssh -i ~/.ssh/仕事用_rsa -F /dev/null"

※git2.1.0以降のみ設定可能

参考

https時代のgitアカウントを使い分ける方法

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