Connecting to Multiple GitHub Acounts

Allow your device to access multiple GitHub accounts simultanously.

Generate SSH key pair and add to GitHub

ssh-keygen -t rsa -C [email] -f ~/.ssh/[filename]
ssh-keygen -t rsa -C username@gmail.com -f ~/.ssh/github
  • -t | Specify encryption type, usually rsa (legacy) or ed25519 (current)
  • -C | Email used to authenticate to your GitHub account
  • -f | Specify filename for new SSH keys

The command above will create two files:

  • ~/.ssh/github - Your SSH Private Key
  • ~/.ssh/github.pub - Your SSH Public Key
cat ~/.ssh/github.pub
⚠️
Make sure to add public SSH keys to GitHub

Modify SSH Config File

Open ~/.ssh/config file using vim. If it does not exist it then it will create one. Then configure the file using the example below (modify to your use case):

vim ~/.ssh/config
Host github.com
  HostName github.com
  User git
  IdentityFile ~/.ssh/ssh_keys_github

Host arapitech.com
  HostName arapitech.com
  User git
  IdentityFile ~/.ssh/ssh_keys_arapitech

Add Remote Branch and Clone

Go back to your working directory and add the remote branch

git remote add origin <ssh url from GitHub>
git remote add origin git@github.com:myUserName/myRepo.git
git clone git@github.com:myUserName/myRepo.git
About the author

Arapi Tech

Networking + DevOps + Programming

Arapi Tech Blog

Great! You’ve successfully signed up.

Welcome back! You've successfully signed in.

You've successfully subscribed to Arapi Tech Blog.

Success! Check your email for magic link to sign-in.

Success! Your billing info has been updated.

Your billing was not updated.