<?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: Luciano Lima</title>
    <description>The latest articles on DEV Community by Luciano Lima (@rushiano).</description>
    <link>https://dev.to/rushiano</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%2F1014262%2Fea832fe2-5692-4176-b6a9-be2a8fe35bdb.png</url>
      <title>DEV Community: Luciano Lima</title>
      <link>https://dev.to/rushiano</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/rushiano"/>
    <language>en</language>
    <item>
      <title>Using Multiple SSH Keys</title>
      <dc:creator>Luciano Lima</dc:creator>
      <pubDate>Tue, 10 Oct 2023 16:51:48 +0000</pubDate>
      <link>https://dev.to/rushiano/using-multiple-ssh-keys-46fb</link>
      <guid>https://dev.to/rushiano/using-multiple-ssh-keys-46fb</guid>
      <description>&lt;p&gt;Hi everyone! This is my first post and I'm here to talk about SSH and the pain it is to use it sometimes. So let's go directly to the point. Have you ever had the feeling you can´t use GitHub and GitLab at the same time on your devices through SSH? Well, you can!&lt;/p&gt;

&lt;h2&gt;
  
  
  First Things First
&lt;/h2&gt;

&lt;p&gt;Enter &lt;code&gt;ls -al ~/.ssh&lt;/code&gt; and if the output is like&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;id_rsa.pub
id_ecdsa.pub
id_ed25519.pub
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It means that you have the folder we need and also you already have the default keys in place (we're not using those).&lt;/p&gt;

&lt;h2&gt;
  
  
  Creating Your Keys
&lt;/h2&gt;

&lt;h3&gt;
  
  
  GitHub
&lt;/h3&gt;

&lt;p&gt;On your terminal enter&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;ssh-keygen -f ~/.ssh/id_ed25519_github -t ed25519 -C "your_email@example.com"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;For some old systems you'll have to use RSA, so do this instead&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;ssh-keygen -f ~/.ssh/id_rsa_github -t rsa -b 4096 -C "your_email@example.com"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In both ways, they're gonna ask you for names and passwords but I just press ENTER and move on.&lt;/p&gt;

&lt;h3&gt;
  
  
  GitLab
&lt;/h3&gt;

&lt;p&gt;Same thing. At terminal we enter&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;ssh-keygen -f ~/.ssh/id_ed25519_gitlab -t ed25519 -C "your_email@example.com"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;For RSA&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;ssh-keygen -f ~/.ssh/id_rsa_gitlab -t ed25519 -C "your_email@example.com"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Add Your Keys To ssh-agent
&lt;/h2&gt;

&lt;p&gt;Be sure that it is running&lt;br&gt;
&lt;/p&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;p&gt;And now enter the name of the keys you registered&lt;br&gt;
GitHub&lt;br&gt;
&lt;/p&gt;

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

&lt;/div&gt;



&lt;p&gt;GitLab&lt;br&gt;
&lt;/p&gt;

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

&lt;/div&gt;



&lt;p&gt;ATTENTION: If you're using the RSA one be sure to put the correct names of the files.&lt;/p&gt;

&lt;h2&gt;
  
  
  Register your SSH Key
&lt;/h2&gt;

&lt;h3&gt;
  
  
  GitHub
&lt;/h3&gt;

&lt;h4&gt;
  
  
  Terminal
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;Enter the ssh filter with &lt;code&gt;cd ~/.ssh&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Type &lt;code&gt;cat id_ed25519_github.pub&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Copy the content
#### Web Site&lt;/li&gt;
&lt;li&gt;Click your photo profile&lt;/li&gt;
&lt;li&gt;Settings&lt;/li&gt;
&lt;li&gt;SSH and GPG Keys&lt;/li&gt;
&lt;li&gt;New SSH Key&lt;/li&gt;
&lt;li&gt;Give the registry a name on the Title&lt;/li&gt;
&lt;li&gt;Paste the key that you copied from the terminal on the key&lt;/li&gt;
&lt;li&gt;Add SSH Key&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  GitLab
&lt;/h3&gt;

&lt;h4&gt;
  
  
  Terminal
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;Enter the ssh filter with &lt;code&gt;cd ~/.ssh&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Type &lt;code&gt;cat id_ed25519_gitlab.pub&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Copy the content
#### Web Site&lt;/li&gt;
&lt;li&gt;Click your photo profile&lt;/li&gt;
&lt;li&gt;Settings&lt;/li&gt;
&lt;li&gt;SSH Keys&lt;/li&gt;
&lt;li&gt;Paste the key that you copied from the terminal on the key&lt;/li&gt;
&lt;li&gt;Give the registry a name on the Title&lt;/li&gt;
&lt;li&gt;Add key&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  The Config File
&lt;/h2&gt;

&lt;p&gt;Now is the tricky part. When you're using the keys on .ssh there is no config file so you need to create one.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Enter the .ssh folder with &lt;code&gt;cd ~/.ssh&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Create a file with &lt;code&gt;touch config&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Now open the file with  &lt;code&gt;nano config&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Paste the configuration below
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# GITHUB
Host github.com
   HostName github.com
   PreferredAuthentications publickey
   IdentityFile ~/.ssh/id_ed25519_github

# GITLAB
Host gitlab.com
   HostName gitlab.com
   PreferredAuthentications publickey
   IdentityFile ~/.ssh/id_ed25519_gitlab
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Sometimes: ERROR
&lt;/h3&gt;

&lt;p&gt;GitHub likes to make us lose some hair over configuration and sometimes you'll get some errors like:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;kex_exchange_identification: read: connection reset by peer ubuntu
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If the error has &lt;strong&gt;kex_exchange_identification&lt;/strong&gt; try these changes on the config file:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# GITHUB
Host github.com
   HostName ssh.github.com
   PreferredAuthentications publickey
   IdentityFile ~/.ssh/id_ed25519_github
   Port 443
   User git

# GITLAB
Host gitlab.com
   HostName gitlab.com
   PreferredAuthentications publickey
   IdentityFile ~/.ssh/id_ed25519_gitlab
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If you set the port to 443 and put the "ssh." on HostName&lt;/p&gt;

&lt;p&gt;Also, there is this annoying possibility you get a permission error. To fix that set your config file to 600:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;cd ~/.ssh
chmod 600 config
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  123 Testing
&lt;/h2&gt;

&lt;p&gt;Now you try &lt;code&gt;ssh -T git@github.com&lt;/code&gt; and &lt;code&gt;ssh -T git@gitlab.com&lt;/code&gt; and see if the message is a friendly one. &lt;/p&gt;

&lt;p&gt;The best part is that you can add more versioning sites to use your keys and help with productivity (and also you'll be way less annoyed :) )&lt;/p&gt;

&lt;p&gt;PS: If you're still getting errors like the "bad owner or permission" one, try &lt;code&gt;chmod 600 ~/.ssh/config&lt;/code&gt;.&lt;/p&gt;

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