Giter Club home page Giter Club logo

use-multiple-github-accounts-with-ssh-keys's Introduction

Easiest way to use multiple github accounts with ssh keys

Here are the steps to use multiple github accounts on same machine. Let's assume that we have 2 github accounts.

  • github.com/mygit
  • github.com/companygit

1. Clear all cached ssh keys

ssh-add -D

2. Generate ssh keys for both mygit and companygit and add them to your github accounts.

ssh-keygen -t rsa -C "id_rsa_mygit"
ssh-keygen -t rsa -C "id_rsa_companygit"

NOTE: Replace "id_rsa_mygit" and "id_rsa_companygit" with your own words. (e.g. ssh-keygen -t rsa -C "id_rsa_orkiv")

3. Add ssh keys to the authentication agent.

ssh-add ~/.ssh/id_rsa_mygit
ssh-add ~/.ssh/id_rsa_companygit

4. Configure ssh aliases.

touch ~/.ssh/config

Open up ~/.ssh/config file with command-line editor. (e.g. sudo nano ~/.ssh/config)

Add the following configuration.

Host github.com-mygit
	HostName github.com
	User git
	IdentityFile ~/.ssh/id_rsa_mygit

Host github.com
	HostName github.com
	User git
	IdentityFile ~/.ssh/id_rsa_companygit

NOTE: For the 2nd account, the Host is github.com. Why?

When I use another name(e.g. Host github.com-companygit), the first Host(for mygit) was invoked for the other hosts and getting the following error.

ERROR: Permission to [companygit/test.git] denied to [mygit].
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

After changing the Host as github.com for the second account, the error was gone.

5. Enjoy yourself.

use-multiple-github-accounts-with-ssh-keys's People

Contributors

brandongalli avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.