Setting up SSH for multiple GIT Accounts
A quick guide through SSH key GIT.

What is a SSH key and why use it?
When working with GitHub we often need to identify ourselves by providing the username and password. An SSH key is an alternative this authentication. By using SSH key we often doesn’t new to verify us by providing the username and password. Instead we can provide the SSH key.
First let’s see how to create a SSH key…
Check for existing SSH keys
- Open terminal
- 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.
Creating a new HSS key .
- If you are using Linux or Mac , open a terminal and if you are using windows open Git Bash
- Paste the following text and substitute your GitHub email address.
$ ssh-keygen -t ed25519 -C "your_email@example.com"
3. When you’re prompted to “Enter a file in which to save the key,” press Enter to accept the default file location.
> Enter a file in which to save the key (/home/you/.ssh/id_ed25519): [Press enter]
4. At the prompt, type a secure passphrase.
> Enter passphrase (empty for no passphrase): [Type a passphrase]
> Enter same passphrase again: [Type passphrase again]
Adding your SSH key to the ssh-agent
- Start the ssh-agent in the background.
$ eval "$(ssh-agent -s)"
2. Add your SSH private key to the ssh-agent.
$ ssh-add ~/.ssh/id_ed25519
# replace your id_ed25519 with you relevant id
Adding the SSH key to your GitHub account
- 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 clipboardFor windows users
$ clip < ~/.ssh/id_ed25519.pub
# Copies the contents of the id_ed25519.pub file to your clipboardFor mac users
$ pbcopy < ~/.ssh/id_ed25519.pub
# Copies the contents of the id_ed25519.pub file to your clipboard
2. Go to your GitHub account and go to Settings then SSH and GPG Keys then click new SSH key .
3. In the “Title” field, add a descriptive label for the new key. eg-: “Personal MacBook Air”
4. Paste the copied SSH key and click Add SSH key.
In the above way you can create new SSH keys for other GitHub accounts and add them to the relevant account. Like that when you have multiple accounts and SSH keys do as follows…
5. Edit/Create ssh config file (~/.ssh/config
):
$ ~/.ssh/config
# check whether the config file existsif not create
$ cd ~/.ssh/
$ touch config // Creates the file if not exists
$ code config // Opens the file in VS code, use any editor
6. Make configuration entries for the relevant GitHub accounts as follows
# 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>
7. Clone your projects
$ 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.
This is a quick guide on setting up SSH for multiple GIT Accounts. There are lot more to learn. Keep going on learning.
Cheers!!!!