LoginSignup
29
19

More than 5 years have passed since last update.

GitHubのDeploy Keyで複数Repositoryに接続する方法

Posted at

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

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できるはず

29
19
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
29
19