<?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>DEV Community: Halibal</title>
    <description>The latest articles on DEV Community by Halibal (@halibal).</description>
    <link>https://dev.to/halibal</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%2F1351902%2Fbd08e41d-51b4-41a2-af56-3f3e5131f89d.jpeg</url>
      <title>DEV Community: Halibal</title>
      <link>https://dev.to/halibal</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/halibal"/>
    <language>en</language>
    <item>
      <title>Resolving SSH Key Issues for Yarn Install with GitHub</title>
      <dc:creator>Halibal</dc:creator>
      <pubDate>Mon, 14 Oct 2024 11:17:53 +0000</pubDate>
      <link>https://dev.to/halibal/resolving-ssh-key-issues-for-yarn-install-with-github-4ocg</link>
      <guid>https://dev.to/halibal/resolving-ssh-key-issues-for-yarn-install-with-github-4ocg</guid>
      <description>&lt;h1&gt;
  
  
  SSH Key Issue Resolution for Yarn Install with GitHub
&lt;/h1&gt;

&lt;h2&gt;
  
  
  Overview
&lt;/h2&gt;

&lt;p&gt;When running &lt;code&gt;yarn install&lt;/code&gt; in a project that required fetching dependencies over SSH from GitHub, the installation process failed with a &lt;code&gt;Permission denied (publickey)&lt;/code&gt; error. This document outlines the steps followed to resolve the issue, including troubleshooting SSH keys, passphrase prompts, and configuring the environment for a successful installation.&lt;/p&gt;

&lt;h2&gt;
  
  
  Problem
&lt;/h2&gt;

&lt;p&gt;When attempting to install dependencies via &lt;code&gt;yarn&lt;/code&gt;, an error occurred when Git tried to access a private repository through SSH. The error looked like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git@github.com: Permission denied (publickey).
fatal: Could not read from remote repository.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Further investigation revealed that while the correct SSH key was being offered, the passphrase prompt could not be handled in the non-interactive environment of &lt;code&gt;yarn&lt;/code&gt;, resulting in the following error:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;debug1: read_passphrase: can't open /dev/tty: No such device or address
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Steps to Resolve
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Step 1: Ensure SSH Agent Is Running
&lt;/h3&gt;

&lt;p&gt;First, verify that the SSH agent is running, which is necessary for managing and using SSH keys without needing to enter the passphrase repeatedly.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Open &lt;strong&gt;PowerShell&lt;/strong&gt; and run the following command:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight powershell"&gt;&lt;code&gt;&lt;span class="w"&gt;  &lt;/span&gt;&lt;span class="n"&gt;Get-Service&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;ssh-agent&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If the service is not running, start it:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight powershell"&gt;&lt;code&gt;&lt;span class="w"&gt;  &lt;/span&gt;&lt;span class="n"&gt;Start-Service&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;ssh-agent&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;If you encounter an issue trying to configure the SSH agent to start automatically, such as an &lt;code&gt;Access is denied&lt;/code&gt; error when running the following:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight powershell"&gt;&lt;code&gt;&lt;span class="w"&gt;  &lt;/span&gt;&lt;span class="n"&gt;Set-Service&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;ssh-agent&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nt"&gt;-StartupType&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;Automatic&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Make sure PowerShell is run &lt;strong&gt;as Administrator&lt;/strong&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  Step 2: Add SSH Key to the Agent
&lt;/h3&gt;

&lt;p&gt;Load the SSH key into the agent to avoid passphrase prompts during &lt;code&gt;yarn&lt;/code&gt; commands.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Add the key to the agent:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight powershell"&gt;&lt;code&gt;&lt;span class="w"&gt;  &lt;/span&gt;&lt;span class="n"&gt;ssh-add&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="bp"&gt;$HOME&lt;/span&gt;&lt;span class="nx"&gt;\.ssh\id_ed25519&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If prompted, enter your passphrase to cache it for future use. After this step, the key will be automatically used in SSH connections, without requiring manual input.&lt;/p&gt;

&lt;h3&gt;
  
  
  Step 3: Test SSH Authentication
&lt;/h3&gt;

&lt;p&gt;To ensure that your SSH key is correctly set up and that GitHub can authenticate with it, test the SSH connection:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Run:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight powershell"&gt;&lt;code&gt;&lt;span class="w"&gt;  &lt;/span&gt;&lt;span class="n"&gt;ssh&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nt"&gt;-T&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;git&lt;/span&gt;&lt;span class="err"&gt;@&lt;/span&gt;&lt;span class="nx"&gt;github.com&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You should see a message like:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;  Hi username! You've successfully authenticated, but GitHub does not provide shell access.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Step 4: Run Yarn Install with Verbose SSH Debugging
&lt;/h3&gt;

&lt;p&gt;To troubleshoot why the &lt;code&gt;yarn install&lt;/code&gt; command was failing, run the command with verbose SSH logging to see exactly what's happening during the process:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Set the environment variable and run:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight powershell"&gt;&lt;code&gt;&lt;span class="w"&gt;  &lt;/span&gt;&lt;span class="nv"&gt;$&lt;/span&gt;&lt;span class="nn"&gt;env&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="nv"&gt;GIT_SSH_COMMAND&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"ssh -v"&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="n"&gt;yarn&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;install&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This provided detailed information, including the issue that &lt;code&gt;yarn&lt;/code&gt; could not open &lt;code&gt;/dev/tty&lt;/code&gt; to prompt for the SSH key's passphrase, which caused the failure.&lt;/p&gt;

&lt;h3&gt;
  
  
  Step 5: Remove Passphrase from SSH Key (Optional, if needed)
&lt;/h3&gt;

&lt;p&gt;Since the key's passphrase was causing issues in the non-interactive &lt;code&gt;yarn install&lt;/code&gt; environment, removing the passphrase from the SSH key provided a solution.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Run the following command to remove the passphrase from your SSH key (replace the path as necessary):
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight powershell"&gt;&lt;code&gt;&lt;span class="w"&gt;  &lt;/span&gt;&lt;span class="n"&gt;ssh-keygen&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nt"&gt;-p&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nt"&gt;-f&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;C:\Users\USER\.ssh\id_ed25519&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You will be prompted to enter the current passphrase and then leave the new passphrase blank by pressing &lt;code&gt;Enter&lt;/code&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  Step 6: Re-run Yarn Install
&lt;/h3&gt;

&lt;p&gt;Once the passphrase was removed, the key no longer required manual input, and &lt;code&gt;yarn install&lt;/code&gt; completed successfully without further errors.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Run:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight powershell"&gt;&lt;code&gt;&lt;span class="w"&gt;  &lt;/span&gt;&lt;span class="n"&gt;yarn&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;install&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;By ensuring the SSH agent was running, loading the SSH key into the agent, and removing the passphrase from the SSH key, the issues with &lt;code&gt;yarn install&lt;/code&gt; and SSH authentication were resolved. This approach eliminates the need for interactive passphrase entry, enabling automated installations without errors.&lt;/p&gt;

&lt;h3&gt;
  
  
  Notes
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;If you want to keep a passphrase on your SSH key, you will need to configure the system to prompt for the passphrase before running any &lt;code&gt;yarn&lt;/code&gt; or &lt;code&gt;git&lt;/code&gt; commands, or ensure the key is added to the SSH agent before any non-interactive commands.&lt;/li&gt;
&lt;li&gt;If you face issues again, start by ensuring the SSH agent is running and your keys are loaded using the &lt;code&gt;ssh-add&lt;/code&gt; command.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://gist.github.com/halibal/620be21f14502b3e88d283ac8ef792b6" rel="noopener noreferrer"&gt;See it on GitHub Gists&lt;/a&gt; &lt;/p&gt;

</description>
      <category>ssh</category>
      <category>yarninstall</category>
      <category>github</category>
      <category>passphrase</category>
    </item>
  </channel>
</rss>
