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

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

More than 1 year has passed since last update.

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

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
ユーザーは見つかりませんでした