LearninBits

How to connect my windows machine to GitHub using SSH

Using SSH to connect your Windows machine to GitHub is a secure way to interact with your repositories without having to enter your credentials every time. Here’s a step-by-step guide to connect your Windows machine to GitHub using SSH:

Check for Existing SSH Keys:

Before you generate a new SSH key, you should check if you have any existing SSH keys.

1. Open Git Bash (if you have it installed). If you don’t have it, you might consider installing Git for Windows which includes Git Bash.

2. Enter `ls -al ~/.ssh` to see if existing SSH keys are present.

3. Check the directory listing to see if you already have a public SSH key. By default, the filenames of the public keys are one of the following:

    – id_dsa.pub

    –id_ecdsa.pub

    – id_ed25519.pub

    – id_rsa.pub

If you don’t have an existing public and private key pair, or don’t wish to use any available keys for GitHub, then proceed with the next step.

Generate a New SSH Key:

1. In Git Bash, enter the following, substituting in your GitHub email address:

ssh-keygen -t ed25519 -C "example@learninbits.com"

– When prompted to “Enter a file in which to save the key,” press Enter. This accepts the default file location.

– At the prompt, type a secure passphrase or press Enter for no passphrase.

Add Your SSH Key to the ssh-agent:

1. Ensure the ssh-agent is running:

eval $(ssh-agent -s)

2. Add your SSH private key to the ssh-agent:

ssh-add ~/.ssh/id_ed25519

Add Your SSH Key to Your GitHub Account:

1. Copy the SSH public key to your clipboard by running the command below:

clip < ~/.ssh/id_ed25519.pub

2. Log in to your GitHub account.

3. Click on your profile picture in the upper right corner and select “Settings.”

4. In the user settings sidebar, click on “SSH and GPG keys.”

5. Click the “New SSH key” button.

6. In the “Title” field, add a descriptive label for the new key. For example, “My Personal Laptop.”

7. Paste your key into the “Key” field.

8. Click the “Add SSH key” button.

Test the Connection:

1. In Git Bash, enter:

ssh -T git@github.com

2. You might see a warning like this:

The authenticity of host 'github.com (IP_ADDRESS)' can't be established.

RSA key fingerprint is SHA256:********************************.

Are you sure you want to continue connecting (yes/no)?

3. Verify the fingerprint in the message you see matches GitHub’s, then type `yes`.

4. If everything went well, you’ll receive a message like:

Hi [your_username]! You've successfully authenticated, but GitHub does not provide shell access.

That’s it! You’ve now set up your Windows machine to connect to GitHub using SSH. This means that when you push, pull, or clone a repository, you won’t need to enter your GitHub credentials every time. Just make sure you use the SSH URL (which starts with `git@github.com:`) when cloning or adding remotes.

1 Comment

  • How to Clone a GitHub Repository Using SSH on Windows - LearninBits August 6, 2023 at 4:22 pm

    […] a previous article, we walked you through how to set up SSH to connect your Windows machine to GitHub. Once you have SSH set up, you can easily clone repositories without entering your credentials […]

Leave a Reply

Layer 1