How To Set Up Multiple SSH Keys on Your Computer (2024)

How To Set Up Multiple SSH Keys on Your Computer (3)

Hello! I was inspired to write this article as I stumbled upon some issues when setting up multiple SSH keys.

I originally had it set up for my personal GitHub. A few days ago, I started to volunteer for one of the non-profit organizations that required another set of SSH key pairs. What I didn’t know is that I was not supposed to overwrite the old SSH key pairs with my new ones and expect them to work. I was working on one of my personal projects the other day and attempted to push to GitHub, but my terminal told me: “Permission denied (publickey).” After spending countless hours Googling, I was able to fix the problem and learned from my mistakes. I am going to walk you through this, so you can set up yours quickly and efficiently.

Step 1: Double-check if you have an existing SSH key.
Step 2a: If you don’t have an existing SSH key, generate a new SSH key
Step 2b: Save the SSH key in the according file of your choice.
Step 3: Add the SSH to the ssh-agent
Step 4: Add your SSH private key to the ssh-agent
Step 5 It depends: Add the SSH key to your GitHub account
Step 6 Optional: To double-check if your git is connecting to your server

Step 1: Double-check if you have an existing SSH key.

★ Open Terminal (Git Bash for Windows users.)

★ Enter ls ~/.ssh (/.ssh/ is a hidden folder. You can access it via Terminal, or Mac: cmd + shift + . ; Windows: check Show Hidden Files)

How To Set Up Multiple SSH Keys on Your Computer (4)

Step 2a: If you don’t have an existing SSH key, generate a new SSH key

★ Enter either ssh-keygen -t ed25519 -C "your_email@example.com" (substitute the email with your associated email with GitHub) or simply ssh-keygen for other hosts.

★ You should see Generating public/private ed25519 key pair if it’s for GitHub, or Generating public/private rsa key pair.

How To Set Up Multiple SSH Keys on Your Computer (5)

PAUSE!!

Normally, you would simply press Enter(or Return for Mac users) to continue as the SSH key would store in the default file the prompt has assigned (id_rsa). However, since we are setting up multiple SSH keys, we would like to name the keys differently, so you can distinguish which one is which and also for later purposes.

Step 2b: Save the SSH key in the according file of your choice.

How To Set Up Multiple SSH Keys on Your Computer (6)

Unfortunately, you have to type the whole pathname to where you want to save it and make sure to name the keys differently.

All right, now press Enter! You should see Enter passphrase(empty for no passphrase):. It is totally up to you if you want to have a passphrase or not. Otherwise, you could press Enter and Enter when you see this: Enter same passphrase again: to skip the process of entering any passphrase.

How To Set Up Multiple SSH Keys on Your Computer (7)

You should see something like this 👆🏻

Step 3: Adding the SSH to the ssh-agent

Mac User: According to the GitHub documentation, if you are adding the SSH key to the agent, use the default macOS ssh-add command.

I assume that you got the config file within your ssh folder, since this is not your first time setting up the SSH key.

If you don’t or you simply want to double-check, you could:

★ Start the ssh-agent in the background eval "$(ssh-agent -s)"

How To Set Up Multiple SSH Keys on Your Computer (8)

Don’t worry, you and I would have a different Agent pid number.

★ Check to see if your ~/.ssh/config exists.

★ You could type ls within the ~/.ssh/

(I am sorry, Windows users. I don’t know much from this point, but according to GitHub, you can skip this part and go straight to setting up the private key.)

★ Type vim config. This will open the config file, no matter if you have that file or not. You can edit the config file using the Vim text editor.

How To Set Up Multiple SSH Keys on Your Computer (9)

★ Once you are on this page, press i so you can insert your ssh-agent. And hold Option (alt on Windows) on your keyboard and click wherever you want to copy and paste the following items.

For GitHub, you can copy and paste the following:

Host *
AddKeysToAgent yes
UseKeychain yes
IdentityFile ~/.ssh/id_rsa_github2 <- change this to whatever you name your ssh-key, in my case, it would be id_rsa_github2

If you are using other sites, like AWS CodeCommit, you would need to find the according ssh-agent name:

Host git-codecommit.*.amazonaws.com 
User APKAEIBAERJR2EXAMPLE <- You would find this when you upload the SSH key and it's under SSH Key ID
IdentityFile ~/.ssh/codecommit_rsa <- change this to whatever you name your ssh-key

After vim config

★ Once you are done, press esc on your keyboard to leave the “insert” mode and type :wq and then Enter to exit the text editor.

How To Set Up Multiple SSH Keys on Your Computer (10)

Step 4: Add your SSH private key to the ssh-agent

ssh-add -K ~/.ssh/id_rsa_github2

Step 5 It depends: Add the SSH key to your GitHub account

Here are a detailed instructions and guidance from GitHub that you can follow.

Step 6 Optional: To double-check if your git is connecting to your server

(That’s what I went for after I set up my key.)

In the case of GitHub, type the following:

ssh -T GITHUB-USERNAME@github.com

If you got Permission denied (publickey) , go ahead and copy and paste:

ssh -T git@github.com
> Hi username! You've successfully authenticated...

If you still got Permission denied , you might want to check your SSH keys whether it’s set up properly in your host agent, your config, etc. More info here specifically for GitHub.

Step 7: Repeat the instructions if you have to (Back to Step 1)

If you have more SSH keys to set up, simply repeat the instructions above and you should be good to go 😉. I would also recommend double-checking with the instructions of the host agent that you are trying to connect with. This article is a general case if you are curious about how to set up multiple SSH keys.

NOTE: I would appreciate any comments if I have missed anything. I would love to include Windows users in this article. Let me know what else you did to make it work!

How To Set Up Multiple SSH Keys on Your Computer (11)
How To Set Up Multiple SSH Keys on Your Computer (2024)

FAQs

How To Set Up Multiple SSH Keys on Your Computer? ›

In the context of rotating SSH keys for security purposes, it is recommended to have at least two sets of SSH keys and change them every 60-90 days. By doing so, you ensure that even if one key is compromised, you still have a backup set of keys to maintain secure access to the server.

How do I add another SSH key in Windows? ›

For Windows 10 & 11
  1. Press the Windows key or open up the Start Menu. Type “cmd”.
  2. Under “Best Match”, click “Command Prompt”.
  3. In the command prompt, use the ssh-keygen command: ...
  4. The system will now generate the key pair and display the key fingerprint and a randomart image. ...
  5. Open your file explorer.

How many SSH keys should I create? ›

In the context of rotating SSH keys for security purposes, it is recommended to have at least two sets of SSH keys and change them every 60-90 days. By doing so, you ensure that even if one key is compromised, you still have a backup set of keys to maintain secure access to the server.

How to use different SSH keys for different accounts? ›

How to Use Multiple SSH Keys For Different Git Accounts
  1. 1 – Create a New SSH Key. The first thing you will need is an SSH key that will be added to your corresponding Github account. ...
  2. 2 – Add SSH Key to Github Account. ...
  3. 3 – Modify SSH config. ...
  4. 4 – Associate Repository to New Key. ...
  5. 5 – Set User For Current Repository.
Dec 29, 2022

Can you have multiple SSH keys on one computer? ›

If you wish to gain regular access to the Git Fusion host, you can specify the correct key in your ssh command. Alternatively, you can manage multiple SSH keys using the SSH 'config' file on your local machine. This file is located at '~/. ssh/config' when using Linux, Mac or 'Git Bash' on Windows.

How do I add a SSH key to another computer? ›

Here is the process using an External Drive or USB thumb drive:
  1. Copy your private key (typically ~/. ...
  2. Copy your public key (typically ~/. ...
  3. Carry the USB stick to your new workstation.
  4. Make the ~/. ...
  5. Change the permissions of the ~/. ...
  6. Copy your private key from the USB stick to your ~/.

How do I create a different SSH key? ›

Generating a new SSH key
  1. Open Terminal .
  2. Paste the text below, replacing the email used in the example with your GitHub email address. ssh-keygen -t ed25519 -C "your_email@example.com" ...
  3. At the prompt, type a secure passphrase. For more information, see "Working with SSH key passphrases."

How do I add more SSH keys? ›

Table of Contents
  1. Step 1: Double-check if you have an existing SSH key. ...
  2. Step 2a: If you don't have an existing SSH key, generate a new SSH key. ...
  3. Step 2b: Save the SSH key in the according file of your choice. ...
  4. Step 3: Adding the SSH to the ssh-agent. ...
  5. Step 4: Add your SSH private key to the ssh-agent.

Do you need a new SSH key for each computer? ›

It would be safer to create new key and invalidate the old one in bitbucket configuration, but you can reuse it. It is enough to copy private and public part of the key from previous computer to a new one. Disk location should be ${home}/. ssh where ${home} depends on your operating system.

What is the best practice for SSH keys? ›

It should never be shared or transmitted over insecure networks. Consider encrypting private keys with a passphrase for additional security. Rotate SSH keys. Just like passwords, SSH keys should be changed or rotated regularly to reduce the risk of a key being used maliciously if it's compromised and unnoticed.

Can two users use the same SSH key? ›

So, No - you'll need a separate key for each account. Although you need multiple ssh key pairs for multiple accounts you can configure multiple ssh identities and use via aliases on your machine. You can also just use your username in place of "git" or "hg". Still need separate keys, though.

How many SSH keys can each user have assigned? ›

The Secure Shell Key page displays the hash of the SSH public key associated with each user. Each user can have only one key assigned.

Which of the two SSH keys Cannot be transferred to anyone? ›

The id_rsa is the private key, don't want to give this key to anyone. In this case, since we are going to generate two ssh keys, we don't want to keep the default file name, set it to whatever name you want by giving it /Users/sprlwrks/. ssh/file_name .

Should I use one SSH key for everything? ›

Yes, a single private key can be used to log in to multiple Linux systems. It's even recommended to do so. The process is very straightforward. When you use an utility such as ssh-keygen, this generates a so-called private/public key pair.

Can you have multiple SSH connections at once? ›

You can configure as many connections/groups as you need in EasySSH, which makes remote connections to an entire data center's worth of Linux machines very easy. And that's all there is to make the management of multiple SSH connections considerably more efficient.

Are SSH keys computer specific? ›

In terms of usage, while SSH private keys are not inherently machine-specific, they can be configured within different systems to act as machine-specific keys if required. By doing so, you can enhance the security of your connections by ensuring that only authorized machines can establish a secure shell communication.

How do I add an additional SSH key? ›

Table of Contents
  1. Step 1: Double-check if you have an existing SSH key. ...
  2. Step 2a: If you don't have an existing SSH key, generate a new SSH key. ...
  3. Step 2b: Save the SSH key in the according file of your choice. ...
  4. Step 3: Adding the SSH to the ssh-agent. ...
  5. Step 4: Add your SSH private key to the ssh-agent.

How do I add a new SSH key to my server? ›

How to add new SSH key to a cloud server
  1. Connect to the server using your current key. ssh cloud-user@1.2.3.4 -i /current_private_ssh_key.
  2. Add a public key to the "authorized_keys" file. You can add a public key to the "authorized_keys" file using "nano" text editor (or any text editor of your choice): ...
  3. Verify new key.

How to add existing keys for SSH? ›

Adding SSH Key to SSH Agent
  1. Check if SSH Agent is running. eval "$(ssh-agent -s)"
  2. Add the Keys to SSH Agent. ssh-add ~/.ssh/nameofkey.
  3. Verify Keys Added to SSH Agent. ssh-add -l.
  4. Copy Key to Remote Server. ssh-copy-id user@remote.server.location.
  5. Copy Server Key to Host. ssh-copy-id user@host.local.
Mar 22, 2022

How do I add multiple keys in Authorized_Keys? ›

Yes, you can use multiple keys in the authorized_keys file. In the authorized_keys file, add the new key in a new line and then save the file.

Top Articles
What Percentage of Retirees Have a Million Dollars? - SmartAsset
Token Smart Contracts: How to Create a Brand New Token
Spasa Parish
Rentals for rent in Maastricht
159R Bus Schedule Pdf
Sallisaw Bin Store
Black Adam Showtimes Near Maya Cinemas Delano
Www.myschedule.kp.org
Ascension St. Vincent's Lung Institute - Riverside
Understanding British Money: What's a Quid? A Shilling?
Xenia Canary Dragon Age Origins
Momokun Leaked Controversy - Champion Magazine - Online Magazine
Maine Coon Craigslist
‘An affront to the memories of British sailors’: the lies that sank Hollywood’s sub thriller U-571
Tyreek Hill admits some regrets but calls for officer who restrained him to be fired | CNN
Haverhill, MA Obituaries | Driscoll Funeral Home and Cremation Service
Rogers Breece Obituaries
Ems Isd Skyward Family Access
Elektrische Arbeit W (Kilowattstunden kWh Strompreis Berechnen Berechnung)
Omni Id Portal Waconia
Kellifans.com
Banned in NYC: Airbnb One Year Later
Four-Legged Friday: Meet Tuscaloosa's Adoptable All-Stars Cub & Pickle
Model Center Jasmin
Ice Dodo Unblocked 76
Is Slatt Offensive
Labcorp Locations Near Me
Storm Prediction Center Convective Outlook
Experience the Convenience of Po Box 790010 St Louis Mo
Fungal Symbiote Terraria
modelo julia - PLAYBOARD
Poker News Views Gossip
Abby's Caribbean Cafe
Joanna Gaines Reveals Who Bought the 'Fixer Upper' Lake House and Her Favorite Features of the Milestone Project
Tri-State Dog Racing Results
Navy Qrs Supervisor Answers
Trade Chart Dave Richard
Lincoln Financial Field Section 110
Free Stuff Craigslist Roanoke Va
Stellaris Resolution
Wi Dept Of Regulation & Licensing
Pick N Pull Near Me [Locator Map + Guide + FAQ]
Crystal Westbrooks Nipple
Ice Hockey Dboard
Über 60 Prozent Rabatt auf E-Bikes: Aldi reduziert sämtliche Pedelecs stark im Preis - nur noch für kurze Zeit
Wie blocke ich einen Bot aus Boardman/USA - sellerforum.de
Infinity Pool Showtimes Near Maya Cinemas Bakersfield
Dermpathdiagnostics Com Pay Invoice
How To Use Price Chopper Points At Quiktrip
Maria Butina Bikini
Busted Newspaper Zapata Tx
Latest Posts
Article information

Author: Foster Heidenreich CPA

Last Updated:

Views: 5516

Rating: 4.6 / 5 (76 voted)

Reviews: 91% of readers found this page helpful

Author information

Name: Foster Heidenreich CPA

Birthday: 1995-01-14

Address: 55021 Usha Garden, North Larisa, DE 19209

Phone: +6812240846623

Job: Corporate Healthcare Strategist

Hobby: Singing, Listening to music, Rafting, LARPing, Gardening, Quilting, Rappelling

Introduction: My name is Foster Heidenreich CPA, I am a delightful, quaint, glorious, quaint, faithful, enchanting, fine person who loves writing and wants to share my knowledge and understanding with you.