77
66

More than 5 years have passed since last update.

同じサーバで、複数のGitHubリポジトリにDeploy keysを登録する

Posted at

複数のリポジトリに、同じ公開鍵をDeploy keysに登録しようとすると"Key is already in use"って怒られます。というわけで、同じサーバであっても複数のリポジトリのデプロイが出来るように設定をする方法をメモっておきます。

複数の鍵を生成する

$ ssh-keygen -f ~/.ssh/repo_a
$ ssh-keygen -f ~/.ssh/repo_b

これで2つの公開鍵が生成されます。repo_a.pubrepo_b.pubですね。これらをGitHubのリポジトリDeploy keysに登録します。

SSH接続先の設定をする

生成した公開鍵をそれぞれ使い分けたいので、適当にホスト名を決めて設定をします。

~/.ssh/config
Host github-repo-a
  User git
  Port 22
  HostName github.com
  IdentityFile ~/.ssh/repo_a
  TCPKeepAlive yes
  IdentitiesOnly yes

Host github-repo-b
  User git
  Port 22
  HostName github.com
  IdentityFile ~/.ssh/repo_b
  TCPKeepAlive yes
  IdentitiesOnly yes

cloneする場合は、こんな感じでホスト名を置き換えてあげればOKです。簡単ですね。

$ git clone git@github-repo-a:example/repo-a.git
$ git clone git@github-repo-b:example/repo-b.git
77
66
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
77
66