DEV Community

No Face
No Face

Posted on

5

Setup SSH for Github using PowerShell

This is a tutorial on how to setup SSH connection for GitHub using PowerShell.

  1. Generate the SSH key.

     ssh-keygen -t ed25519 -C "email@sample.com"
    

    When you're prompted to "Enter a file in which to save the key", you can press Enter to accept the default file location which is: C:\Users\<windows UserName>/.ssh/id_ed25519, or you can specify your desired file location / file name.

    When done, 2 files should be generated.
    1 private key file and 1 public key file (file with .pub extension).

  2. Start up the ssh-agent.

     Start-Service ssh-agent
    
  3. Add the SSH Key to the ssh-agent.

     ssh-add <path to your private SSH Key>
    
     # if you generate to the default file location
     ssh-add c:/Users/<WindowsUserName>/.ssh/id_ed25519
    
  4. Clip / Copy your public SSH key.

     Get-Content c:/Users/<WindowsUserName>/.ssh/id_ed25519.pub | Set-Clipboard
    
  5. Add your public key to your github account.
    5.1. In the upper-right corner of any page, click your profile photo, then click Settings.

    5.2. In the "Access" section of the sidebar, click SSH and GPG keys.

    5.3. Click New SSH key or Add SSH key.

    5.4. In the "Title" field, add a descriptive label for the new key.

    5.5. In the "Key" field, paste your public key.

    5.6. Click Add SSH key.

  6. Test the connection.

     ssh -T git@github.com
    

    You might see a warning like this.

     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)?
    

    if so, verify that the fingerprint the message matches you public key fingerprint. And if it does, type yes then enter.

    If successful, you should see a message like this.

     Hi <github userName>! You've successfully authenticated, but GitHub does not provide shell access.
    

Extra

After setting up your SSH, and still could not connect or keeps getting an error (especially the error below.)

...
git@github.com: Permission denied (publickey).
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.
...
Enter fullscreen mode Exit fullscreen mode

Try setting up your SSH config.

Setting up SSH config

Go to your c:/Users/<WindowsUseName>/.ssh directory and check if a config file (no extension) is present.

If not, create one. If it already exist, edit.
And in the file, add the following text.

Host *
    Hostname github.com
    IdentityFile ~/.ssh/<private key filename>
Enter fullscreen mode Exit fullscreen mode

Then try accessing git again.

Hope this helps!

--- END ---

Jetbrains image

Don’t Become a Data Breach Headline

57% of organizations have suffered from a security incident related to DevOps toolchain exposures. Is your CI/CD protected? Check out these nine practical tips to keep your CI/CD secure—without adding friction.

Learn more

Top comments (1)

Collapse
 
german_cardenas_d37d4455a profile image
German Cardenas

Great! Thanks for sharing.

FYI, I had to run this command before starting ssh service

Set-Service -Name ssh-agent -StartupType Automatic

Just if you want to add it in case someone else faces that issue

Image of Stellar post

How a Hackathon Win Led to My Startup Getting Funded

In this episode, you'll see:

  • The hackathon wins that sparked the journey.
  • The moment José and Joseph decided to go all-in.
  • Building a working prototype on Stellar.
  • Using the PassKeys feature of Soroban.
  • Getting funded via the Stellar Community Fund.

Watch the video

👋 Kindness is contagious

Dive into this informative piece, backed by our vibrant DEV Community

Whether you’re a novice or a pro, your perspective enriches our collective insight.

A simple “thank you” can lift someone’s spirits—share your gratitude in the comments!

On DEV, the power of shared knowledge paves a smoother path and tightens our community ties. Found value here? A quick thanks to the author makes a big impact.

Okay