Qiita Teams that are logged in
You are not logged in to any team

Log in to Qiita Team
Community
OrganizationAdvent CalendarQiitadon (β)
Service
Qiita JobsQiita ZineQiita Blog
15
Help us understand the problem. What is going on with this article?
@narikei

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

15
Help us understand the problem. What is going on with this article?
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
narikei
なんでも屋さん

Comments

No comments
Sign up for free and join this conversation.
Sign Up
If you already have a Qiita account Login
15
Help us understand the problem. What is going on with this article?