Setting up SSH for multiple GIT Accounts

Photo by Silas Köhler on Unsplash
  1. Open terminal
  2. Check for existing keys
 $ ls -al ~/.ssh# If you already have an SSH key, you can use it to connect to github. Else make a new one.
  1. If you are using Linux or Mac , open a terminal and if you are using windows open Git Bash
  2. Paste the following text and substitute your GitHub email address.
$ ssh-keygen -t ed25519 -C "your_email@example.com"
> Enter a file in which to save the key (/home/you/.ssh/id_ed25519):   [Press enter]
> Enter passphrase (empty for no passphrase): [Type a passphrase]
> Enter same passphrase again: [Type passphrase again]
  1. Start the ssh-agent in the background.
$ eval "$(ssh-agent -s)"
$ ssh-add ~/.ssh/id_ed25519
# replace your id_ed25519 with you relevant id
  1. Copy the SSH public key to your clipboard.
For Linux users
$ sudo apt-get install xclip
# Downloads and installs xclip.

$ xclip -selection clipboard < ~/.ssh/id_ed25519.pub
# Copies the contents of the id_ed25519.pub file to your clipboard
For windows users
$ clip < ~/.ssh/id_ed25519.pub
# Copies the contents of the id_ed25519.pub file to your clipboard
For mac users
$ pbcopy < ~/.ssh/id_ed25519.pub
# Copies the contents of the id_ed25519.pub file to your clipboard
$ ~/.ssh/config
# check whether the config file exists
if not create
$ cd ~/.ssh/
$ touch config // Creates the file if not exists
$ code config // Opens the file in VS code, use any editor
# Personal account 
Host github.com-Personal
HostName github.com
User git
IdentityFile ~/.ssh/<key for the Personal account>

# Work account
Host github.com-Work
HostName github.com
User git
IdentityFile ~/.ssh/<key for Work account>
$ git clone git@github.com-Personal:<personal_account_name>/<repo_name.git>
# Replace "github.com" with your Personal account host name given in the config file.
$ git clone git@github.com-Work:<Work_account_name>/<repo_name.git>
# Replace "github.com" with your work account host name given in the config file.

--

--

--

Undergraduate at Faculty of IT University of Moratuwa

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

Recommended from Medium

{UPDATE} Spider Solitaire ? Hack Free Resources Generator

How to Defense against Common Web Attacks

Airdrops | Huobi Primelist × LaunchBlock: 100,000 $LBP Shared!

$FEN Token Shooting star on BitMart!

Logical and Physical attacks on ATM

Multi-bit public key encryption with Learning With Errors (LWE)

Russian Hackers On The Move: Demanding Liberal Groups For Hush Money

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
Thisuri Bandaranayake

Thisuri Bandaranayake

Undergraduate at Faculty of IT University of Moratuwa

More from Medium

Version Control Git

Pitfalls I Encountered Building a REST API

GIT Branching