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 [email protected] -f id_rsa
ssh-keygen -t rsa -C [email protected] -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 [email protected] (RSA)
2048 6d:65:b9:3b:ff:9c:5a:54:1c:2f:6a:f7:44:03:84:3f [email protected] (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 [email protected]
H Rossbu! You've successfully authenticated, but GitHub does not provide shell access.
$ ssh -T [email protected]
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 = [email protected]
touch ~/.gitconfig-work , edit with below content
[user]
name = work_user
email = [email protected]
Step 7: Clone personal and work codebases
bash
$ mkdir ~/perosnal && cd ~/personal && git clone [email protected]:rossbu/email-service.git
$ mkdir ~/work && cd ~/work && git clone [email protected]: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