Skip to content

Instantly share code, notes, and snippets.

@rudyhuynh
Forked from jexchan/multiple_ssh_setting.md
Last active October 19, 2020 03:02
Show Gist options
  • Save rudyhuynh/a28fd56235b0e78dfce047b64a9bf8a0 to your computer and use it in GitHub Desktop.
Save rudyhuynh/a28fd56235b0e78dfce047b64a9bf8a0 to your computer and use it in GitHub Desktop.
Multiple SSH keys for different github accounts

Multiple SSH Keys settings for different git account

This instruction helps create multiple ssh keys for local machine to use multiple git remote repositories.

Step 1: Create different ssh keys

$ ssh-keygen -t rsa -C "your_email1@youremail.com"
$ ssh-keygen -t rsa -C "your_email2@youremail.com"

Step 2: Create file config at ~/.ssh

Host bitbucket.org
    HostName bitbucket.org
    User git
    IdentityFile ~/.ssh/user1

Host git.everymatrix.com
    HostName git.everymatrix.com
    User git
    IdentityFile ~/.ssh/id_rsa

Step 3: Clone your repo and modify your Git config (Can skip this step if Host == HostName)

Checkout .git/config: Update Host in origin to the Host that defined in ~/.ssh/config

[remote "origin"]
    url = git@bitbucket.org:activehacker/gfs.git
    ...

Make sure @bitbucket.org to match config host

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment