Cloning git with multiple Github accounts using SSH

Lee young-jun
3 min readNov 21, 2021

--

Few years ago Github didn’t allow private repository to personal.
So I had to use Gitlab private repository,
but now Github provides same feature.

Therefore I decided to transfer all my repository to Github and apply SSH.
However there was a big problem.

I am already using SSH to access olulo’s repository to working in home.
This time I will share you how to use multiple Github accounts with SSH.

Setup SSH

Check existing SSH Keys

Check if you already have any SSH Key.
Keep in mind that Generating SSH Key can overwrite your exist key.

ls ~/.ssh

The files like id_xxx is your SSH Key

Generate new SSH Key

  1. ssh-keygen -t ed25519 -C "Your Github account email"
  2. If you would use XCode also, use rsa instead of ed25519 like this
    ssh-keygen -t rsa -b 4096 -C "Your Github account email"
  3. Input location to save a new key
    Enter a file in which to save the key (/Users/you/.ssh/id_algorithm):
    - If you just press ‘Enter’, it will be default like id_{algorithm name}
  4. Input password to the new key
    Enter passphrase (empty for no passphrase):

Configure SSH Key

open or create SSH configuration file
vi ~/.ssh/config

Configure Default SSH Key

Host * <- all host
- AddKeysToAgent yes
- UseKeychain yes
- IdentityFile {location of key file}

You can access repository without entering password each time with AddKeysToAgent , UseKeychain option.

Configure secondary SSH Key

Host olulo.github.com <--  git host alias
- HostName github.com <-- real git host name
- IdentityFile ~/.ssh/id_ed25519_olulo <-- secondary key file
- User olulo <-- secondary user name

You can adds secondary SSH Key with Host and HostName

Register SSH Key

  • Copy public Key file
    pbcopy < ~/.ssh/{id_xxx}.pub
    - this will copy content of the public key file into clipboard
  • Github Settings
  • Settings > SSH and GPG Keys
  • SSH and GPG Keys > New SSH key
  • Paste copied key and press Add SSH Key
Title is for distinguishing.

Clone with SSH

  • Repository > Code > SSH
  • Modify copied Git SSH url

git@olulo.github.com:team-olulo/kickgoing-app.git

  • Input password for SSH key

Congratulations!

Now you can work with multiple Github accounts in you Mac

Reference

Connecting to GitHub with SSH — GitHub Docs

--

--

Responses (1)