, ,
Share On

Claps upto fifty times for each post.

20


GitHub SSH key setup takes Five minutes.

You can set up Multiple GitHub accounts on a single device using SSH key

Having to maintain multiple GitHub accounts for your projects might be time-consuming. Or GitHub SSH key setup is time-consuming for us. When we clone a new repository from a particular account that does not have access to the private repository, it is a little difficult for beginners like me to figure out.

Consider that you have two different GitHub profiles, such as “account1@domain.com” and “account2@github.com.” An SSH key setup can assist you if you wish to copy a private repository from Account1 that won’t be accessible from Account2.

Alternatively, if you belong to a private organization and experience issues like this:


Initialized empty Git repository in `/Users/username/Documents/Repo/YourRepo.git/` Permission denied (publickey).
fatal: The remote end hung up unexpectedly

SSH key setup is a must!

That is also very simple to accomplish. We’ll set up the SSH key on our local machine in five minutes.

Table of content

1: Check existing key
2: Setup a new key
3. Save the key to GitHub
4. Config the account on the local machine

SSH key Setup started


Step 1: Check the existing key

Open the terminal on the root directory

Run command:

cd .ssh

You can check available SSH setups as well by command ls

If there is no .ssh file present, run this command:

ssh-keygen -t rsa

Then press the return key to complete the setup.

ls 

If you already have some key setup, then you will get like this

You can update those or create a new SSH key to config.

Step 2: Setup a new key

create a new key with this command

 ssh-keygen -f user_id_1

You may use anything to identify your account as the ‘user id 1’ in this case refers to your SSH key. After creating new SSH, you can check by command ls , and then it will show like

user_id_1  user_id_1.pub

There will be a public key to use. Generate the SSH key by this command

cat user_id_1.pub

It will generate a long SSH key, copy from the beginning to = (equal sign). For example SSH key will look alike

ssh key

3. Save the key to GitHub

Go to your GitHub account and then settings >> create a new SSH key, paste copied SSH key. You can follow the settings page: https://github.com/settings/keys

github ssh setup

4. Config the account on the local machine

back to the terminal again and set up a config file. First, create a config file by

touch config

Then open the config file and write the host, hostname, and identifier like this. You can copy the code below and replace the user_id_1 part with your SSH key name.

#Account1
Host github.com
HostName github.com
IdentityFile ~/.ssh/user_id_1

Congratulations, Your SSH key setup is done.

Multiple GitHub SSH (account) setup:

You must create more SSH keys for multiple accounts using the same process. Create a new SSH by the command below.

 ssh-keygen -f user_id_2

Then generate a new key by

cat user_id_2.pub

To create a new SSH using the generated id, copy the SSH key and proceed to your GitHub settings. Follow step 3

Back to the terminal and setup the config file for another account by writing the config file

#Account1
Host github.com
HostName github.com
IdentityFile ~/.ssh/user_id_1

#Account2
Host github.com-account2
HostName github.com
IdentityFile ~/.ssh/user_id_2

Save the file before exiting! All done 🥳

Manage multiple account access:

You can clone by ssh from GitHub using Account 1 and Account 2 like this
copy the SSH URL, then clone from account 1: git clone git@github.com:hasanuzzamanbe/php-environment-setup-for-mac.git (Nothing changed for account 1)

From account 2: git clone git@github.com-account2:hasanuzzamanbe/php-environment-setup-for-mac.git Just add the host before the repository name here account2 is the host slug.

Your SSH setup for GitHub is done! You can set up more accounts following this procedure as well.



If you have any trouble setting up the PHP environment on your Mac or if you want to install WordPress locally. You can follow this article as well
https://wpminers.com/how-to-install-laravel-valet-on-mac/


Leave a Reply

Your email address will not be published. Required fields are marked *

Hasanuzzaman Avatar

Click to follow this author!


Posts by this author


Posts related this

Share your local WordPress site.

AKM Elias

24 February 2024

Dynamic programming part – 1(Memoization)

AKM Elias

30 October 2022

Let’s install Laravel valet on ubuntu

hasanmisbah

27 September 2022

GitHub SSH key setup takes Five minutes.

Hasanuzzaman

14 September 2022

How to Install Laravel Valet on Mac

Hasanuzzaman

21 August 2022