Skip to content

Instantly share code, notes, and snippets.

@tomeraz
Last active January 2, 2018 08:26
Show Gist options
  • Save tomeraz/166e9e7b98d6f39fc19659a6b64e0979 to your computer and use it in GitHub Desktop.
Save tomeraz/166e9e7b98d6f39fc19659a6b64e0979 to your computer and use it in GitHub Desktop.
Multiple repositories github setup

Multiple repositories github setup

1. Generate deploy keys

$ ssh-keygen -t rsa -b 4096
Generating public/private rsa key pair.
Enter file in which to save the key (/home/user/.ssh/id_rsa): repo1_rsa
Enter passphrase (empty for no passphrase):
Enter same passphrase again:

Your identification has been saved in repo1_rsa.
Your public key has been saved in repo1_rsa.pub.
The key fingerprint is:
03:b5:da:08:3b:6f:9a:29:3f:f5:4c:ee:5d:14:cb:41 user@host
The key's randomart image is:
+–[ RSA 4096]—-+
some output
+—————–+

2. Same for another repo

3. Edit ssh config

$ nano ~/.ssh/config

# Global SSH configurations here will be applied to all hosts
IdentityFile ~/.ssh/repo1_rsa
IdentityFile ~/.ssh/repo2_rsa
    
Host    repo1.github.com
    HostName github.com
    PreferredAuthentications publickey
    IdentityFile    ~/.ssh/repo1_rsa

Host    repo2.github.com
    HostName github.com
    PreferredAuthentications publickey
    IdentityFile    ~/.ssh/repo2_rsa

4. Add keys to ssh-agent - for some reason this needs to be on every session

$ eval "$(ssh-agent -s)" && ssh-add ~/.ssh/repo1_rsa
$ eval "$(ssh-agent -s)" && ssh-add ~/.ssh/repo2_rsa
or use this zsh plugin:

https://github.com/robbyrussell/oh-my-zsh/tree/master/plugins/ssh-agent

5. Clone repos

git clone git@repo1.github.com:repo1/project.git
git clone git@repo2.github.com:repo2/project.git
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment