Skip to content

Instantly share code, notes, and snippets.

@rossbu
Last active August 27, 2021 05:52
Show Gist options
  • Save rossbu/9df6b128648294b5123f51ce9d0c2e3a to your computer and use it in GitHub Desktop.
Save rossbu/9df6b128648294b5123f51ce9d0c2e3a to your computer and use it in GitHub Desktop.
Multiple SSh Account
Step 1: create ssh keys
Create any keypairs you'll need. I've named my default/original 'id_rsa' (which is the default) and 'id_rsa-work' for company work.
ssh-keygen -t rsa -C ross.bu@gmail.com -f id_rsa
ssh-keygen -t rsa -C ross.bu@work.com -f id_rsa_work
Step 2: ssh config
Set up multiple ssh profiles by creating/modifying ~/.ssh/config. Note the slightly differing 'Host' values
# Personal GitHub
Host github.com
AddKeysToAgent yes
UseKeychain yes
User git
HostName github.com
PreferredAuthentications publickey
IdentityFile ~/.ssh/id_rsa
# Work GitHub
Host work.github.com
AddKeysToAgent yes
UseKeychain yes
User git
HostName github.com
PreferredAuthentications publickey
IdentityFile ~/.ssh/id_rsa_work
Step 3: ssh-add
You may or may not have to do this. To check, list identity fingerprints by running:
bash
$ ssh-add -l
2048 1f:1a:b8:69:cd:e3:ee:68:e1:c4:da:d8:96:7c:d0:6f ross.bu@gmail.com (RSA)
2048 6d:65:b9:3b:ff:9c:5a:54:1c:2f:6a:f7:44:03:84:3f ross.bu@work.com (RSA)
If your entries aren't there then run:
bash
ssh-add ~/.ssh/id_rsa
ssh-add ~/.ssh/id_rsa_work
Step 4: test ssh key
To test you've done this all correctly, I suggest the following quick check:
bash
$ ssh -T git@github.com
H Rossbu! You've successfully authenticated, but GitHub does not provide shell access.
$ ssh -T git@work.github.com
H xxx! You've successfully authenticated, but GitHub does not provide shell access.
Step 5: Add below to ~/.gitconfig
[includeIf "gitdir:~/personal/"]
path = ~/.gitconfig-personal
[includeIf "gitdir:~/work/"]
path = ~/.gitconfig-work
Step 6: Create 2 gitconfig files for each
touch ~/.gitconfig-personal , edit with below content
[user]
name = rossbu
email = ross.bu@gmail.com
touch ~/.gitconfig-work , edit with below content
[user]
name = work_user
email = xxx@work.com
Step 7: Clone personal and work codebases
bash
$ mkdir ~/perosnal && cd ~/personal && git clone git@github.com:rossbu/email-service.git
$ mkdir ~/work && cd ~/work && git clone git@work.github.com:orgname/projectname.git
Step 8 : Open 2 workspaces in IDEA and check if 'PULL REQUEST' menu shows up.
bash
$ cd perosnal && idea .
$ cd work && idea .
https://youtrack.jetbrains.com/issue/IDEA-276812
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment