<?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: l579</title>
    <description>The latest articles on DEV Community by l579 (@l579).</description>
    <link>https://dev.to/l579</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%2F108809%2F54ca9148-c8b7-4162-9403-81fa1b5a9764.png</url>
      <title>DEV Community: l579</title>
      <link>https://dev.to/l579</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/l579"/>
    <language>en</language>
    <item>
      <title>Generate Multiple SSH Keys for Multiple Remote Accounts</title>
      <dc:creator>l579</dc:creator>
      <pubDate>Thu, 22 Nov 2018 12:32:40 +0000</pubDate>
      <link>https://dev.to/l579/generate-multiple-ssh-keys-for-multiple-remote-accounts-140o</link>
      <guid>https://dev.to/l579/generate-multiple-ssh-keys-for-multiple-remote-accounts-140o</guid>
      <description>&lt;p&gt;If you have multiple Bitbucket accounts (let's say one for your company and one private one) and additionally one Github account that you all want to authenticate with SSH, you can follow this guide to add all accounts to your local machine so you don't need to struggle with different accounts anymore.&lt;/p&gt;

&lt;h2&gt;
  
  
  Generate SSH Keys
&lt;/h2&gt;

&lt;p&gt;Open your terminal and navigate to your home directory. Start by generating your first default SSH key.&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 -t rsa
ssh-add ~/.ssh/id_rsa
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Store the keys in the default location.&lt;br&gt;
For each additional account generate new SSH keys but be careful not to overwrite the previously generated one by giving it a new name.&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 -t rsa -C "companyName"
ssh-add ~/.ssh/companyName
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Store this key under the &lt;code&gt;companyName&lt;/code&gt; so when you are asked where to store it, enter the location but exchange the filename.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;/Users/user/.ssh/companyName
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Config
&lt;/h2&gt;

&lt;p&gt;Create a config file or alter the existing one.&lt;br&gt;
&lt;/p&gt;

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

&lt;/div&gt;



&lt;p&gt;In YAML syntax add following entries for your keys.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="s"&gt;Host bitbucket.org&lt;/span&gt;
    &lt;span class="s"&gt;HostName bitbucket.org&lt;/span&gt;
    &lt;span class="s"&gt;IdentityFile ~/.ssh/id_rsa&lt;/span&gt;
    &lt;span class="s"&gt;IdentitiesOnly yes&lt;/span&gt;

&lt;span class="s"&gt;Host companyName.bitbucket.org&lt;/span&gt;
    &lt;span class="s"&gt;HostName bitbucket.org&lt;/span&gt;
    &lt;span class="s"&gt;IdentityFile ~/.ssh/companyName&lt;/span&gt;
    &lt;span class="s"&gt;IdentitiesOnly yes&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Save the configuration file with name &lt;code&gt;config&lt;/code&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Configure Remote Repos
&lt;/h2&gt;

&lt;p&gt;Copy your SSH key for the account you want to use it.&lt;br&gt;
&lt;/p&gt;

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

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;pbcopy &amp;lt; ~/.ssh/companyName.pub
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In Bitbucket, login to your account where you want to add the copied key and navigate to &lt;code&gt;Bitbucket Settings - Security - SSH Keys&lt;/code&gt; and add the key. Repeat for all accounts that you created a key for.&lt;br&gt;
In Github navigate to &lt;code&gt;Settings - SSH and GPG keys&lt;/code&gt; and add your Github key there.&lt;/p&gt;
&lt;h2&gt;
  
  
  Cloning from Company Account
&lt;/h2&gt;

&lt;p&gt;If you clone from your default account just copy the output when you click &lt;code&gt;Clone&lt;/code&gt; inside your remote repository.&lt;br&gt;
If you clone from your company account, you need to alter the host with the host you specified in your &lt;code&gt;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;git clone git@companyName.bitbucket.org:user/repo.git
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>ssh</category>
      <category>repository</category>
      <category>git</category>
      <category>remote</category>
    </item>
  </channel>
</rss>
