Use multiple ssh-keys for different GitHub accounts on the same computer

1. Create a new ssh-key and add it to the work GitHub account

$ ssh-keygen -t rsa -b 4096 -C "my_work_email@my_company.com"

2. Modify the ssh config file ( ~/.ssh/config)

# Personal GitHub account
Host github.com
HostName github.com
User git
AddKeysToAgent yes
UseKeychain yes
IdentityFile ~/.ssh/id_rsa
# Work GitHub account
Host github.com-work
HostName github.com
User git
AddKeysToAgent yes
UseKeychain yes
IdentityFile ~/.ssh/work_rsa

3. Clone the work project repo (with a slightly different address)

$ git clone git@github.com-work:[my work GitHub group]/[my project].git

4. Modify the package.json to install the private repo dependencies

"dependencies": {
"private-module": "git+ssh://git@github.com-work/[private module name].git
...
}
$ npm install git+ssh://git@github.com-work/[private module name]

Designer turned Software Engineer turned Cloud Architect. Now a Solutions Architect at AWS. Posts are my own.

Love podcasts or audiobooks? Learn on the go with our new app.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Xiaoli Shen

Xiaoli Shen

Designer turned Software Engineer turned Cloud Architect. Now a Solutions Architect at AWS. Posts are my own.

More from Medium

An overview of Git, including what it is and how to use it.

Force merge in Git

Introduction to Data Driven Programming

Git, GitHub Basics