DEV Community

Vijay Thapa
Vijay Thapa

Posted on

Unable to Connect Git and Github. So I did this 👇

After 4 years, I came back to programming.

And the first thing I did was try to run my old abandoned project.

Now, I was determined to complete it and share.
So started to complete the unfinished features and give them some final touches.

Once I completed one of the features, I saved the changes on git and tried to push it to Github repository.

Unfortunately I started getting some "Couldn't Connect" type errors.

And it said

You cannot connect git and github with username and password, it deprecated in 2021.

To fix this issue, I did some google search and found a good medium article and a YouTube.

Following those resources I found out that I needed to generate SSH key to connect Git and Github now.

So, I followed the these Steps to connect Git and Github with SSH Keys

1. Generate SSH Keys on My Mac 💻

To generate the SSH keys, I opened thee terminal and executed the following command

ssh-keygen -t Ed25519 -b 256
Enter fullscreen mode Exit fullscreen mode

Once the keys (private and public) are generated, it'll ask for the location to save it.
You can save it in default location by pressing Enter.

Then you'll have to give a passphrase.
You can press Enter if you don't want to add it.

But it's recommended to add a passphrase.

Note: When you push to Github you may need to enter the Passphrase. So you need to remember it.

If you want to check or see the existing SSH keys, use the following command

ls -al ~/.ssh
Enter fullscreen mode Exit fullscreen mode

2. Display the Public Key
After you generated the SSH keys, you need to copy it.
For that you can use the following command to display the public key

cat ~/.ssh/id_ed25519.pub
Enter fullscreen mode Exit fullscreen mode

Then copy the displayed public key from the terminal.

3. Add the Public SSH Key to Github
Now, Log In to Github and then go to Settings and then to SSH and GPG Keys
Link: https://github.com/settings/keys

Then click on New SSH Key

Now, Give Title to your new SSH Key and paste the public SSH key that you copied from Step 2 👆 .

Add New SSH Keys to Github

4. Activate SSH agent
Now, in your terminal you need to activate the SSH agent.
For that, use the following command

ssh-add
Enter fullscreen mode Exit fullscreen mode

Hope it's helpful to you.

Resources I referenced

YouTube Video: https://www.youtube.com/watch?v=ESi3pj1iznQ

Medium Article: https://medium.com/codex/git-authentication-on-macos-setting-up-ssh-to-connect-to-your-github-account-d7f5df029320

Top comments (0)