Set Up SSH Keys on Windows: A Step-by-Step Guide

C

Chidubem Okoli

Guest
Secure Shell (SSH) is a security protocol that creates a highly secure connection between your computer and GitHub. It uses a pair of cryptographic keysβ€”a public key you share and a private key you keep safeβ€”to verify your identity.

The main benefit of using SSH keys is convenience and security. Once set up, you can connect to GitHub to push and pull code without having to enter your username and personal access token every time.

Here's a step-by-step guide on how to set up your SSH keys in a Windows environment.

Step 1: Check for Existing SSH Keys
First, let's see if you already have an SSH key pair. It's good practice to avoid creating new ones if you don't have to.

a) Open PowerShell (press the Windows key, type PowerShell, and press Enter).

b) The default directory is /.ssh. Run the following command to list files in the .ssh directory, which is where keys are typically stored:


Code:
ls -a ~/.ssh

c) Look for a pair of files named something like id_rsa and id_rsa.pub, or id_ed25519 and id_ed25519.pub. If you see a .pub file, you already have a key and can skip to Step 3.

Alternatively, you can get the key by typing into the powershell terminal


Code:
cat id_ed25519.pub

Step 2: Generate a New SSH Key Pair

If you don't have an existing key, you'll need to create one. We'll generate a modern and secure Ed25519 key.

a) In your PowerShell terminal, run the following command. Make sure to replace "[email protected]" with the email address associated with your GitHub account.


Code:
ssh-keygen -t ed25519 -C "[email protected]"

b) The command will prompt you to choose a location to save the key. The default location (~/.ssh/id_ed25519) is perfect, so just press Enter.

c) Next, you'll be asked to enter a passphrase. πŸ”


  • A passphrase adds an extra layer of security; if someone gains access to your computer, they still can't use your key without knowing the passphrase.


  • It's highly recommended to use one, but you can leave it blank by pressing Enter twice.

Code:
> Enter passphrase (empty for no passphrase): [Type a passphrase]
> Enter same passphrase again: [Type passphrase again]

You've now created two files in your ~/.ssh directory: id_ed25519 (your private key) and id_ed25519.pub (your public key). Never share your private key!

Step 3: Add Your SSH Key to the ssh-agent
The ssh-agent is a background program that securely stores your private key and manages its passphrase so you don't have to re-enter it constantly.

a) First, ensure the ssh-agent service is running. This command will start it if it isn't active.


Code:
Start-SshAgent

b) Now, add your private SSH key to the agent.


Code:
ssh-add ~/.ssh/id_ed25519

c) If you created a passphrase in the previous step, you will be prompted to enter it now.

Step 4: Add Your Public SSH Key to GitHub
Now you need to tell GitHub about your public key so it can grant you access.
a) Now you need to copy your public SSH key. To do this, we’re going to use a command called cat to read the file to the console.


Code:
cat ~/.ssh/id_ed25519.pub

b) Open your browser and navigate to GitHub.


  • Click your profile picture in the top-right corner, then click Settings.


  • In the left sidebar, click SSH and GPG keys.

c) Click the New SSH key button.

d) In the Title field, give your key a descriptive name, like "My Windows Laptop" or "Work PC".

e) Click inside the Key field and paste your key by pressing Ctrl + V.

f) Finally, click Add SSH key. You may be asked to enter your GitHub password to confirm.

Step 5: Test Your SSH Connection
Let's make sure everything is working correctly.

a) Back in your PowerShell terminal, run this command:


Code:

b) You may see a warning about the authenticity of the host. This is normal for the first connection.


Code:
The authenticity of host 'github.com (IP ADDRESS)' can't be established.
ED25519 key fingerprint is SHA256:+DiY3wvvV6TuJJhbpZisF/zLDA0zPMSvHdkr4UvCOqU.
Are you sure you want to continue connecting (yes/no/[fingerprint])?

Type yes and press Enter.

c) If everything is set up correctly, you'll see a welcome message with your username! πŸŽ‰


Code:
Hi your-username! You've successfully authenticated, but GitHub does not provide shell access.

You're all set! You can now clone, pull, and push to your GitHub repositories using SSH without needing to enter your credentials every time.

Continue reading...
 


Join 𝕋𝕄𝕋 on Telegram
Channel PREVIEW:
Back
Top