Help us understand the problem. What is going on with this article?

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

More than 5 years have passed since last update.

複数のリポジトリに、同じ公開鍵を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
zaru
basicinc
マーケティングとテクノロジーで社会のあらゆる問題を解決する集団
https://tech.basicinc.jp/
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
No comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
ユーザーは見つかりませんでした