GitHubのDeploy Keyに公開鍵を登録しようとすると。
Key is already in use
とか怒られて登録できない。
他で使っている鍵は登録できなないのだけど、
Jenkinsとか複数のプライベートリポジトリーにアクセスしたい場合、
ssh configで接続先を変えて対処します。
例えば repository-second
というリポジトリーの場合
鍵を作成
$ ssh-keygen -f ~/.ssh/repository-second
ssh configに追記
もしconfigがなかったらファイルを作成する。
$ touch ~/.ssh/config
$ chmod 600 ~/.ssh/config
$ vim ~/.ssh/config
~/.ssh/config
Host github-repository-first
User git
Port 22
HostName github.com
IdentityFile ~/.ssh/repository-first
TCPKeepAlive yes
IdentitiesOnly yes
Host github-repository-second
User git
Port 22
HostName github.com
IdentityFile ~/.ssh/repository-second
TCPKeepAlive yes
IdentitiesOnly yes
GithubのDeploy Keysに公開鍵を登録する
$ cat ~/.ssh/repository-second.pub
の中身を登録する
![Screen Shot 2018-07-12 at 12.41.07.png](https://qiita-user-contents.imgix.net/https%3A%2F%2Fqiita-image-store.s3.amazonaws.com%2F0%2F7132%2Fc512300f-cc66-a2e3-e050-a09e5b57697b.png?ixlib=rb-4.0.0&auto=format&gif-q=60&q=75&s=abd150e7a2e99c9bd2626a8f725559c0)
GitHubにアクセス
接続先のホスト名をconfigで指定したホスト名に変更します。
git@github.com:narikei/repository-second.git
↓
git@github-repository-second:narikei/repository-second.git
これで、
$ git clone git@github-repository-second:narikei/repository-second.git
でcloneできるはず