<?xml version="1.0" encoding="utf-8"?>
<?xml-stylesheet type="text/xsl" href="../assets/xml/rss.xsl" media="all"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Diego A. Carrasco Gubernatis | Personal Website (Posts about github)</title><link>https://diegocarrasco.com/</link><description></description><atom:link href="https://diegocarrasco.com/categories/github.xml" rel="self" type="application/rss+xml"></atom:link><language>en</language><copyright>Contents © 2026 &lt;a href="mailto:hi@diegocarrasco.com"&gt;Diego Carrasco G.&lt;/a&gt; </copyright><lastBuildDate>Tue, 13 Oct 2026 08:04:50 GMT</lastBuildDate><generator>Nikola (getnikola.com)</generator><docs>http://blogs.law.harvard.edu/tech/rss</docs><item><title>How to use multiple SSH keys on a Mac with Github or Gitlab</title><link>https://diegocarrasco.com/how-to-use-multiple-ssh-keys-on-a-mac-with-github-or-gitlab/</link><dc:creator>Diego Carrasco G.</dc:creator><description>&lt;p&gt;&lt;strong&gt;A quick note on how to use multiple SSH Keys (Identities) on one machine.&lt;/strong&gt;&lt;/p&gt;
&lt;h3 id="a-short-note-on-the-use-case"&gt;A short note on the use case&lt;/h3&gt;
&lt;p&gt;Why would you want to use multiple keys on a machine you ask? There are
several reasons, one being perceived security and another being convenience.
Using just one Identity makes everything easier and you don’t have to manage
several Identities You can read more
&lt;a href="https://security.stackexchange.com/questions/40050/best-practice-%0Aseparate-ssh-key-per-host-and-user-vs-one-ssh-key-for-all-hos" title="Best Practice: ”separate ssh-key per host and user“ vs. ”one ssh-key for all hosts“"&gt;here&lt;/a&gt; and
&lt;a href="https://superuser.com/questions/121307/is-it-reasonable-to-have-%0Amultiple-ssh-keys" title="Is it reasonable to have multiple SSH keys?"&gt;here&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;My use case would be that of convenience. I just want to separate work from
personal projects and I would like to use a separate key (nonwork related)
with those projects&lt;/p&gt;
&lt;h3 id="1-create-a-new-public-key"&gt;1. Create a new public key&lt;/h3&gt;
&lt;div class="code"&gt;&lt;pre class="code literal-block"&gt;&lt;span class="n"&gt;ssh&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;keygen&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;t&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;rsa&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;C&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="ss"&gt;"your_email@youremail.com"&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;This public key can be in any path, not just in &lt;code&gt;~/.ssh/&lt;/code&gt; as default/
recommended.&lt;/p&gt;
&lt;p&gt;For security, it is recommended that you assign a unique password to this key.&lt;/p&gt;
&lt;h3 id="add-all-the-keys-to-your-cached-keys"&gt;Add all the keys to your cached keys&lt;/h3&gt;
&lt;div class="code"&gt;&lt;pre class="code literal-block"&gt;ssh-add path-to-key
&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;For example, if you have your new key in &lt;code&gt;~/Documents/ssh_keys/new_key&lt;/code&gt; you
would need to run &lt;code&gt;ssh-add ~/Documents/ssh_keys/new_key&lt;/code&gt;. If you assigned a
password in Setup 1, you will be asked for it.&lt;/p&gt;
&lt;h3 id="step-3-update-create-your-ssh-config"&gt;Step 3: Update/ Create your ssh config&lt;/h3&gt;
&lt;div class="code"&gt;&lt;pre class="code literal-block"&gt;nano ~/.ssh/config
&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;If you already have entries in your ssh config, just add a new entry at the
end of the file. If your file is empty, or you didn’t have any before, just add
the following.&lt;/p&gt;
&lt;div class="code"&gt;&lt;pre class="code literal-block"&gt;Host gitlab-diego
    HostName gitlab.com # or github.com or any other domain
    User your-username # usually the one you use with that domain
    IdentityFile path-to-key
&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;With the example data for GitLab and user &lt;code&gt;diego&lt;/code&gt; this entry would look like
the following:&lt;/p&gt;
&lt;div class="code"&gt;&lt;pre class="code literal-block"&gt;Host gitlab-diego
    HostName gitlab.com
    User diego
    IdentityFile ~/Documents/ssh_keys/new_key
&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;To save and close just press &lt;em&gt;Ctrl + o&lt;/em&gt; and &lt;em&gt;enter&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;To exit &lt;code&gt;nano&lt;/code&gt; press &lt;em&gt;Ctrl + x&lt;/em&gt;.&lt;/p&gt;
&lt;h4 id="step-4-add-the-key-to-gitlab-github-or-other-services"&gt;Step 4: Add the key to GitLab, GitHub or other services&lt;/h4&gt;
&lt;p&gt;In my case, I wanted to use the new key with GitLab. They have &lt;a href="https://gitlab.com/help/ssh/README#adding-an-ssh-key-to-your-%0Agitlab-account" title="Adding an SSH key to your GitLab account"&gt;great
instructions&lt;/a&gt; on how to do that
but, for convenience, I list the steps here:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;Copy your new key to the clipboard.   &lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Log in into gitlab.com and go to &lt;a href="https://gitlab.com/profile/keys"&gt;https://gitlab.com/profile/keys&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;Paste the key into the text box and click on „Add key“  &lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;&lt;strong&gt;&lt;em&gt;Now you may clone a repository using this new key.&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;
&lt;h2 id="references-and-further-reading"&gt;References and further reading&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href="https://gist.github.com/jexchan/2351996" title="Multiple SSH Keys settings for different github account"&gt;Multiple SSH Keys settings for different GitHub account&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://gitlab.com/help/ssh/README#locating-an-existing-ssh-key-pair" title="GitLab and SSH keys"&gt; GitLab and SSH keys&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;</description><category>command-line</category><category>Developer</category><category>English</category><category>github</category><category>how-to</category><category>MacOS</category><guid>https://diegocarrasco.com/how-to-use-multiple-ssh-keys-on-a-mac-with-github-or-gitlab/</guid><pubDate>Sun, 31 May 2020 06:07:39 GMT</pubDate></item></channel></rss>