<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: Ayomide Aluko</title>
    <description>The latest articles on Forem by Ayomide Aluko (@oxayomide_54).</description>
    <link>https://forem.com/oxayomide_54</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F1493879%2Fbc209d11-0c61-4039-89f6-26401b828b57.png</url>
      <title>Forem: Ayomide Aluko</title>
      <link>https://forem.com/oxayomide_54</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/oxayomide_54"/>
    <language>en</language>
    <item>
      <title>How to Set Up SSH Key Authentication with GitHub on Windows</title>
      <dc:creator>Ayomide Aluko</dc:creator>
      <pubDate>Tue, 14 May 2024 15:29:23 +0000</pubDate>
      <link>https://forem.com/oxayomide_54/how-to-set-up-ssh-key-authentication-with-github-on-windows-j23</link>
      <guid>https://forem.com/oxayomide_54/how-to-set-up-ssh-key-authentication-with-github-on-windows-j23</guid>
      <description>&lt;h3&gt;
  
  
  Introduction
&lt;/h3&gt;

&lt;p&gt;In this article, I'll walk through the process of setting up and troubleshooting SSH key authentication for connecting to GitHub repositories on a Windows system using Git Bash. SSH key authentication provides a secure and convenient way to interact with GitHub without entering your username and password repeatedly.&lt;/p&gt;

&lt;h3&gt;
  
  
  Prerequisites
&lt;/h3&gt;

&lt;p&gt;Before you begin, ensure you have the following:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Git installed on your Windows machine. &lt;a href="https://git-scm.com/download/win"&gt;Download here&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;A GitHub account. If you don't have one, you can sign up at &lt;a href="https://github.com/"&gt;GitHub&lt;/a&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Steps to Set Up SSH Key Authentication
&lt;/h3&gt;

&lt;h4&gt;
  
  
  1. Generate SSH Key Pair
&lt;/h4&gt;

&lt;ol&gt;
&lt;li&gt;Open Git Bash on your Windows machine.&lt;/li&gt;
&lt;li&gt;Create a new ssh folder:
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;   &lt;span class="nb"&gt;mkdir &lt;/span&gt;ssh
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;Change your directory into that folder:
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;   &lt;span class="nb"&gt;cd &lt;/span&gt;ssh
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;Generate a new SSH key pair by running the following command:
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;   ssh-keygen &lt;span class="nt"&gt;-t&lt;/span&gt; rsa &lt;span class="nt"&gt;-C&lt;/span&gt; &lt;span class="s2"&gt;"your-email-address"&lt;/span&gt; &lt;span class="nt"&gt;-f&lt;/span&gt; &lt;span class="s2"&gt;"github-username"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Replace with your email address and username associated with your GitHub account.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Optionally, provide a passphrase for extra security.&lt;/li&gt;
&lt;/ol&gt;

&lt;h4&gt;
  
  
  2. Start SSH Agent and Add SSH Key
&lt;/h4&gt;

&lt;ol&gt;
&lt;li&gt;You can now change directory back into your default root:
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;cd&lt;/span&gt; ..
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;Start the SSH agent by running:
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;   eval $(ssh-agent -s)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;Add your SSH private key to the SSH agent:
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;   ssh-add /c/Users/USER/.ssh/id_rsa
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Replace &lt;code&gt;/c/Users/USER/.ssh/id_rsa&lt;/code&gt; with the actual file location.&lt;/p&gt;

&lt;h4&gt;
  
  
  3. Add SSH Public Key to GitHub Account
&lt;/h4&gt;

&lt;ol&gt;
&lt;li&gt;Change directory into the ssh folder again:
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;cd ssh
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;Copy the contents of your SSH public key (&lt;code&gt;id_rsa.pub&lt;/code&gt;):
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;   &lt;span class="nb"&gt;cat &lt;/span&gt;id_rsa.pub
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;replace "id_rsa.pub" with the name of your ssh with the &lt;code&gt;.pub&lt;/code&gt; extension.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Log in to your GitHub account.&lt;/li&gt;
&lt;li&gt;Navigate to &lt;code&gt;Settings &amp;gt; SSH and GPG keys&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Click on &lt;code&gt;New SSH key&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Paste your SSH public key into the &lt;code&gt;Key&lt;/code&gt; field and give it a descriptive title.&lt;/li&gt;
&lt;li&gt;Click &lt;code&gt;Add SSH key&lt;/code&gt; to save.&lt;/li&gt;
&lt;/ol&gt;

&lt;h4&gt;
  
  
  4. Configure SSH for GitHub
&lt;/h4&gt;

&lt;ol&gt;
&lt;li&gt;Change directory into the ssh folder again:
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;cd &lt;/span&gt;ssh
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;Open or create the SSH configuration file (&lt;code&gt;config&lt;/code&gt;) in the &lt;code&gt;.ssh&lt;/code&gt; directory:
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;   &lt;span class="nb"&gt;touch &lt;/span&gt;config.txt
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;it is a normal txt file so fine ways to add the information below to it, you can use vim too.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Add the following SSH configuration for GitHub in the config file:
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;   Host github.com
     HostName github.com
     User git
     IdentityFile "/c/Users/USER/.ssh/id_rsa"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Replace &lt;code&gt;/c/Users/USER/.ssh/id_rsa&lt;/code&gt; with the path to your SSH private key. Don't forget the double quote if you are on windows, use this if you are on mac:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;~/.ssh/id_rsa
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  5. Test SSH Connection to GitHub
&lt;/h4&gt;

&lt;ol&gt;
&lt;li&gt;Test the SSH connection to GitHub:
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;   ssh &lt;span class="nt"&gt;-T&lt;/span&gt; git@github.com
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;If prompted to confirm the authenticity of the host, type &lt;code&gt;yes&lt;/code&gt; and press &lt;code&gt;Enter&lt;/code&gt;.&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  Troubleshooting
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Permission Denied (publickey) Error:&lt;/strong&gt; If you encounter this error, ensure that your SSH key is added to the SSH agent and correctly configured in your GitHub account and SSH configuration file.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Path Formatting (Windows):&lt;/strong&gt; Use forward slashes (&lt;code&gt;/&lt;/code&gt;) and quotes (&lt;code&gt;" "&lt;/code&gt;) for file paths in the SSH configuration file (&lt;code&gt;config&lt;/code&gt;) on Windows.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Conclusion
&lt;/h3&gt;

&lt;p&gt;By following these steps, you should now have SSH key authentication set up and working with GitHub on your Windows machine. This method provides a secure and efficient way to interact with GitHub repositories using Git commands without the need to enter your GitHub credentials repeatedly.&lt;/p&gt;

&lt;p&gt;Feel free to share this article with others who may encounter similar issues when setting up SSH key authentication with GitHub on Windows.&lt;/p&gt;

</description>
      <category>ssh</category>
      <category>github</category>
      <category>webdev</category>
    </item>
  </channel>
</rss>
