DEV Community

No Face
No Face

Posted on

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

Top comments (0)