Github deploy keys: How do I authorize more than one repository for a single machine?

Once a key has been attached to one repo as a deploy key, it cannot be
used on another repo. If you’re running into this error while setting
up deploy keys, then you’ll need to modify your remote and set up your
~/.ssh/config file to use a non-existent hostname that
ssh will be able to use to pick the correct ssh deploy key for your

# first we remove the origin
$ git remote -v
origin (fetch)
origin (push)
$ git remote rm origin

# here we add a new origin using a host nickname called
# that we will reference with a Host stanza in our
# ~/.ssh/config to specify which key to use with which fake hostname.
$ git remote add origin
$ git remote -v
origin (fetch)
origin (push)

Generate the deploy key for your repository and name it something
reasonable like:

$ ssh-keygen -t rsa -f ~/.ssh/id_rsa-foo -C
Generating public/private rsa key pair.
Enter passphrase (empty for no passphrase): 
Enter same passphrase again: 
Your identification has been saved in /home/username/.ssh/id_rsa-foo.
Your public key has been saved in /home/username/.ssh/
The key fingerprint is:
The key's randomart image is:
+--[ RSA 2048]----+
|  E   o..o.oo.   |
| M o o o .+CoW   |
|  + o = o. ..    |
| .   . +         |
|        S        |
|       o .       |
|        +        |
|       . o       |
|        ..o.     |

Once you’ve
added the deploy key
you will then need to add the following stanza to your ~/.ssh/config file:

    IdentityFile ~/.ssh/id_rsa-foo

Now you can test it with:

$ ssh -T
Hi username! You've successfully authenticated, but GitHub
does not provide shell access.

Leave a Comment