<?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: Jiri Benes</title>
    <description>The latest articles on DEV Community by Jiri Benes (@jiri).</description>
    <link>https://dev.to/jiri</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%2F420359%2F95400f91-f3ae-46f4-94a5-c25a497b07b0.jpg</url>
      <title>DEV Community: Jiri Benes</title>
      <link>https://dev.to/jiri</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/jiri"/>
    <language>en</language>
    <item>
      <title>A Step-by-Step Guide to Setting Up Custom SSH Keys for GitHub</title>
      <dc:creator>Jiri Benes</dc:creator>
      <pubDate>Sun, 04 May 2025 14:00:40 +0000</pubDate>
      <link>https://dev.to/jiri/a-step-by-step-guide-to-setting-up-custom-ssh-keys-for-github-4j7e</link>
      <guid>https://dev.to/jiri/a-step-by-step-guide-to-setting-up-custom-ssh-keys-for-github-4j7e</guid>
      <description>&lt;p&gt;Securely connecting to GitHub using SSH keys enhances your workflow by eliminating the need for passwords during authentication. This guide will walk you through generating a key pair, configuring it on GitHub, and troubleshooting common issues.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 1: Generate an SSH Key Pair&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Objective:&lt;br&gt;
&lt;strong&gt;&lt;em&gt;Create a secure SSH key pair (public and private) to authenticate with GitHub.&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Process:&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Open your terminal.&lt;/li&gt;
&lt;li&gt;Run the following command to generate an Ed25519 SSH key pair:&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;em&gt;Generate SSH key with your_custom_file_name!&lt;/em&gt;&lt;br&gt;
&lt;code&gt;ssh-keygen -t ed25519 -f ~/.ssh/file_name -C "your_github@email.address"&lt;/code&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;-f your custom file_name with path&lt;/li&gt;
&lt;li&gt;-C comment ( required | optional)?&lt;/li&gt;
&lt;li&gt;-f output_keyfile&lt;/li&gt;
&lt;li&gt;The -f option specifies the filename for the private key. Choose a meaningful name, like localpc or hostingdomaincom&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Step 2: Add Your Public Key to GitHub&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Objective:&lt;br&gt;
&lt;strong&gt;&lt;em&gt;Authorize your public key for SSH authentication on your GitHub account.&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Process:&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Copy the public key:
&lt;em&gt;Run this command to copy your public key to the clipboard:&lt;/em&gt;
&lt;code&gt;cat ~/.ssh/file_name.pub&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Access GitHub Settings:
&lt;em&gt;Go to GitHub Account Settings .
Click on "Add SSH Key" and provide a title (e.g., "Custom SSH Key").&lt;/em&gt;
&lt;/li&gt;
&lt;li&gt;Paste the public key:
Paste the content of custom_key.pub into the text box.
Click "Add key" to save.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Step 3: Configure SSH to Use Your Custom Key&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Objective:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Tell SSH to use your custom key for connections to GitHub.&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Test your connection
&lt;code&gt;ssh -i ~/.ssh/file_name -T git@github.com&lt;/code&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;2.Edit the SSH configuration file:&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Open the following file in a text editor:&lt;/em&gt;&lt;br&gt;
&lt;code&gt;nano ~/.ssh/config&lt;/code&gt;&lt;br&gt;
&lt;/p&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 ~/.ssh/file_name
    IdentitiesOnly yes
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;Save and exit:
Press &lt;code&gt;Ctrl+O&lt;/code&gt; to write changes.
Press &lt;code&gt;Ctrl+X&lt;/code&gt; to close the editor.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Common Issues &amp;amp; Solutions
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Issue 1: "Permission denied (publickey)" when testing SSH connection&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Ensure your public key is correctly added to GitHub.&lt;/li&gt;
&lt;li&gt;Verify the private key filename in ~/.ssh/config matches the public key.
Testing connection
&lt;code&gt;ssh -T git@github.com&lt;/code&gt;
&lt;code&gt;git@github.com: Permission denied (publickey).&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Testing connection with verbose mode (debug)&lt;br&gt;
&lt;code&gt;ssh -vT git@github.com&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;...
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug1: Authentications that can continue: publickey
debug1: Next authentication method: publickey
debug1: Trying private key: /home/user/.ssh/id_rsa
debug1: Trying private key: /home/user/.ssh/id_ecdsa
debug1: Trying private key: /home/user/.ssh/id_ecdsa_sk
debug1: Trying private key: /home/user/.ssh/id_ed25519
debug1: Trying private key: /home/user/.ssh/id_ed25519_sk
debug1: Trying private key: /home/user/.ssh/id_xmss
debug1: Trying private key: /home/user/.ssh/id_dsa
debug1: No more authentication methods to try.
git@github.com: Permission denied (publickey).
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Github doesn't know your custom file name follow &lt;strong&gt;Step 3&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Check your current remote URL&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;List current remotes:&lt;/em&gt;&lt;br&gt;
&lt;code&gt;git remote -v&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Replace the HTTPS URL with the SSH equivalent in your repository. For example:&lt;br&gt;
bash&lt;/em&gt;&lt;br&gt;
&lt;code&gt;git remote set-url origin git@github.com:username/repo.git&lt;/code&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  Issues: Local "master" Branch Renaming to "main"
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Description:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Commands Used:&lt;/strong&gt;&lt;br&gt;
&lt;code&gt;git push -u origin main&lt;/code&gt;&lt;br&gt;
Error received: "src refspec main does not match any"&lt;br&gt;
&lt;code&gt;git branch -M master main&lt;/code&gt;&lt;br&gt;
&lt;strong&gt;Expected Outcome:&lt;/strong&gt; &lt;br&gt;
&lt;em&gt;Successfully rename the local master branch to main and set it as the default branch for future pushes.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Objectives:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Local git repository with master branch&lt;/li&gt;
&lt;li&gt;Github repository with main branch&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;code&gt;git push -u origin main&lt;/code&gt;&lt;br&gt;
&lt;code&gt;error: src refspec main does not match any&lt;/code&gt;&lt;br&gt;
Rename local "master" branch to "main"&lt;br&gt;
&lt;code&gt;git branch -M main&lt;/code&gt;&lt;br&gt;
git branch help: git branch (-m | -M) [] &lt;br&gt;
_&lt;/p&gt;
&lt;h4&gt;
  
  
  Issue: SSH Agent not open
&lt;/h4&gt;

&lt;p&gt;_&lt;/p&gt;

&lt;p&gt;&lt;code&gt;ssh-add ~/.ssh/your_custom_file_name&lt;/code&gt;&lt;br&gt;
&lt;strong&gt;error: Could not open a connection to your authentication agent.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Solution:&lt;br&gt;
&lt;code&gt;eval "$(ssh-agent -s)"&lt;/code&gt;&lt;br&gt;
&lt;code&gt;ssh-add ~/.ssh/file_name&lt;/code&gt;&lt;br&gt;
&lt;strong&gt;Identity added: /home/&lt;em&gt;user&lt;/em&gt;/.ssh/file_name&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;&lt;strong&gt;To automatically start the SSH agent on login, edit your shell configuration file (e.g., ~/.bashrc) and add:&lt;/strong&gt;&lt;/em&gt;&lt;br&gt;
nvim ~/.bashrc file&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# START Start SSH agent automatically
if [ -z "$SSH_AUTH_SOCK" ]; then
  # Check if ssh-agent is already running
  ps -aux | grep ssh-agent | grep -v grep &amp;gt;/dev/null
  if [ $? -ne 0 ]; then
    # Start ssh-agent
    eval "$(ssh-agent -s)"
  fi
fi
# END Start SSH agent automatically 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
    </item>
  </channel>
</rss>
