Skip to content

Crack SDE

Most of the content are generated by AI, with human being reviewed, edited, and revised

Menu
  • Home
  • Daily English Story
  • Tech Interviews
  • Cloud Native
  • DevOps
  • Artificial Intelligence
Menu

Setup multiple SSH Keys to different github accounts

Posted on 04/22/202404/22/2024 by user

Setting up multiple SSH keys for different GitHub accounts on the same machine is useful if you manage multiple GitHub accounts, such as a personal account and a work account. Here are the steps to configure SSH keys for different GitHub accounts on a single computer:

1. Generate SSH Keys

First, you need to generate a unique SSH key for each GitHub account. Open your terminal and run:

ssh-keygen -t ed25519 -C "your_email@example.com"

When prompted to “Enter a file in which to save the key,” specify a unique path for each key:

# For your first GitHub account
/home/yourusername/.ssh/id_ed25519_github_account1

# For your second GitHub account
/home/yourusername/.ssh/id_ed25519_github_account2

Repeat this for each account, changing the email and file path each time.

2. Add SSH Keys to the SSH Agent

Start the ssh-agent in the background and add your SSH private keys to it:

eval "$(ssh-agent -s)"
ssh-add ~/.ssh/id_ed25519_github_account1
ssh-add ~/.ssh/id_ed25519_github_account2

3. Upload Public Keys to GitHub

For each GitHub account, you need to upload the corresponding public key. You can get the public key using:

cat ~/.ssh/id_ed25519_github_account1.pub

Copy the output and then:

  • Log into your GitHub account.
  • Go to Settings > SSH and GPG keys.
  • Click on “New SSH key”, paste your public key into the field, and save it.

Repeat this for each account.

4. Configure SSH Config File

To make it easy to use different keys with different GitHub accounts, you can set up an SSH config file. Edit or create the config file in your .ssh directory:

nano ~/.ssh/config

Add a configuration block for each GitHub account in the file:

# GitHub Account 1
Host github.com-account1
    HostName github.com
    User git
    IdentityFile ~/.ssh/id_ed25519_github_account1
    IdentitiesOnly yes

# GitHub Account 2
Host github.com-account2
    HostName github.com
    User git
    IdentityFile ~/.ssh/id_ed25519_github_account2
    IdentitiesOnly yes

5. Use SSH Keys

When you clone a repository, use the alias you set in your SSH config file to specify which account and key to use. For example:

git clone git@github.com-account1:username1/repository.git

Replace username1/repository.git with the actual user and repository you wish to clone from the first account. Use the corresponding alias for other accounts.

6. Check SSH Key Usage

To verify which key is being used with GitHub, you can run:

ssh -T git@github.com-account1

This should return a message that you’ve successfully authenticated, but GitHub does not provide shell access.

This setup ensures that you can work with multiple GitHub accounts from the same machine without key conflicts.

Share this:

  • Click to share on Facebook (Opens in new window) Facebook
  • Click to share on X (Opens in new window) X

Related

Recent Posts

  • LC#622 Design Circular Queue
  • Started with OpenTelemetry in Go
  • How Prometheus scrap works, and how to find the target node and get the metrics files
  • How to collect metrics of container, pods, node and cluster in k8s?
  • LC#200 island problem

Recent Comments

  1. another user on A Journey of Resilience

Archives

  • May 2025
  • April 2025
  • February 2025
  • July 2024
  • April 2024
  • January 2024
  • December 2023
  • November 2023
  • October 2023
  • September 2023
  • August 2023
  • June 2023
  • May 2023

Categories

  • Artificial Intelligence
  • Cloud Computing
  • Cloud Native
  • Daily English Story
  • Database
  • DevOps
  • Golang
  • Java
  • Leetcode
  • Startups
  • Tech Interviews
©2025 Crack SDE | Design: Newspaperly WordPress Theme
Manage Cookie Consent
To provide the best experiences, we use technologies like cookies to store and/or access device information. Consenting to these technologies will allow us to process data such as browsing behavior or unique IDs on this site. Not consenting or withdrawing consent, may adversely affect certain features and functions.
Functional Always active
The technical storage or access is strictly necessary for the legitimate purpose of enabling the use of a specific service explicitly requested by the subscriber or user, or for the sole purpose of carrying out the transmission of a communication over an electronic communications network.
Preferences
The technical storage or access is necessary for the legitimate purpose of storing preferences that are not requested by the subscriber or user.
Statistics
The technical storage or access that is used exclusively for statistical purposes. The technical storage or access that is used exclusively for anonymous statistical purposes. Without a subpoena, voluntary compliance on the part of your Internet Service Provider, or additional records from a third party, information stored or retrieved for this purpose alone cannot usually be used to identify you.
Marketing
The technical storage or access is required to create user profiles to send advertising, or to track the user on a website or across several websites for similar marketing purposes.
Manage options Manage services Manage {vendor_count} vendors Read more about these purposes
View preferences
{title} {title} {title}