8

I create a deploy user, generate an ssh_key, I add id_rsa.pub as github deploy key.

this deploy user need pull 2 repo, so I add the same ssh_key to another repo as deploy key.

but github tell me, deploy key already in use.

and I don't know how add 2 id_rsa.pub for 1 user.

update:

I add id_rsa_assets additional, but I still cannot pull.

ssh-add .ssh/id_rsa_assets

Could not open a connection to your authentication agent.

.ssh/config

Host guardians
    Hostname github.com
    User git
    IdentityFile ~/.ssh/id_rsa

Host assets
    Hostname github.com
    User git
    IdentityFile ~/.ssh/id_rsa_assets
Community
  • 1
  • 1
guilin 桂林
  • 17,050
  • 29
  • 92
  • 146
  • Possible duplicate of [github deploy keys: how Do I authorize more than one repository for a single machine](https://stackoverflow.com/questions/11656134/github-deploy-keys-how-do-i-authorize-more-than-one-repository-for-a-single-mac) – Martin Joiner Oct 11 '17 at 18:48

1 Answers1

11

You can create two public/private keys with whatever name you want:

~/.ssh
  repo1
  repo1.pub
  repo2
  repo2.pub

  config

(Ie it doesn't have to be named id_rsa(.pub) to work, provided you indicate ssh where to look.
That is where 'config' comes into play: the config file includes the name of your two connections for GitHub repo1 and GitHub repo2 with, for each connection, the path to your private repo key, as described in "change github account mac command line" and in "Quick Tip: How to Work with GitHub and Multiple Accounts":

Host githubRepo1
HostName github.com
User git
IdentityFile ~/.ssh/repo1

Host githubRepo2
HostName github.com
User git
IdentityFile ~/.ssh/repo2

That way you can pull from any of the two repos, as long as you are using their ssh addresses.

Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • when I run ssh-add ~/.ssh/repo2 it said 'Could not open a connection to your authentication agent.' – guilin 桂林 Apr 06 '12 at 11:54
  • 1
    @guilin桂林: see https://www.cs.indiana.edu/Facilities/FAQ/Security/openssh.html: then your session is not running under the `ssh-agent`. You can get around this by restarting a new shell under the agent by running: `exec ssh-agent bash` where you can replace `bash` with the shell of your choice. Once you do this, you should be able to run `ssh-add` to load your key for that shell. – VonC Apr 06 '12 at 11:57