Logo

dev-resources.site

for different kinds of informations.

Multiple SSH id

Published at
4/14/2024
Categories
ssh
git
github
commit
Author
r4nd3l
Categories
4 categories in total
ssh
open
git
open
github
open
commit
open
Author
6 person written this
r4nd3l
open
Multiple SSH id

Using multiple SSH keys with GitHub allows you to manage access to multiple GitHub accounts or repositories from the same computer or development environment. Here's how you can set it up:

  1. Generate SSH Keys: First, generate SSH keys for each GitHub account or repository you want to access. You can generate SSH keys using the ssh-keygen command in your terminal or command prompt. Make sure to specify a unique name and location for each SSH key pair.
   ssh-keygen -t rsa -b 4096 -C "[email protected]"
Enter fullscreen mode Exit fullscreen mode

When prompted, specify a unique filename for the SSH key pair (e.g., id_rsa_github1, id_rsa_github2, etc.) and optionally set a passphrase for added security.

  1. Add SSH Keys to SSH Agent: Use the ssh-add command to add each SSH private key to the SSH agent. This allows the SSH agent to manage your SSH keys and automatically use them when authenticating with GitHub.
   ssh-add ~/.ssh/id_rsa_github1
   ssh-add ~/.ssh/id_rsa_github2
Enter fullscreen mode Exit fullscreen mode
  1. Configure SSH Config File: Create or edit the SSH config file (~/.ssh/config) to specify which SSH key to use for each GitHub host. You can use the IdentityFile directive to specify the path to the SSH private key.
   # GitHub account 1
   Host github.com
     HostName github.com
     User git
     IdentityFile ~/.ssh/id_rsa_github1

   # GitHub account 2
   Host github-secondaccount
     HostName github.com
     User git
     IdentityFile ~/.ssh/id_rsa_github2
Enter fullscreen mode Exit fullscreen mode

In this example, github-secondaccount is a custom alias for the second GitHub account to avoid conflicts with the default github.com.

  1. Add SSH Public Keys to GitHub: Copy the contents of each SSH public key (id_rsa_github1.pub, id_rsa_github2.pub, etc.) and add them to the SSH keys section in the GitHub account settings.

  2. Test SSH Connection: Finally, test the SSH connection to GitHub to ensure everything is set up correctly.

   ssh -T [email protected]
   ssh -T git@github-secondaccount
Enter fullscreen mode Exit fullscreen mode

You should see a success message confirming the connection to GitHub.

With these steps, you can use multiple SSH keys to authenticate with GitHub and access repositories associated with different GitHub accounts or organizations from the same computer or development environment.

commit Article's
30 articles in total
Favicon
Why I Built commit-ai: A Story About Git Security and Team Safety
Favicon
使用 AI 自動生成 Git Commit 訊息
Favicon
# How to write good commit messages
Favicon
Conventional Git Commits With Best Practices.
Favicon
Understanding Git Rebase Merge: Chronological vs Logical Order and Commit History
Favicon
Improving Commit Message Quality in VSCode with Copilot
Favicon
TIL how to see the entire commit column on GitLab using JS
Favicon
Why Going Back in Git Doesn't Have to Be Scary
Favicon
🤖 Use AI to speed up writing commit messages (bonus: custom prompt for improved generation)
Favicon
How to commit
Favicon
Commits Semânticos: Organizando o Caos com Padrões de Mensagens
Favicon
Consequences of for-Git-ting to merge the master into feature branch!
Favicon
Git: Commit Messages
Favicon
Yazılım Projelerinde Düzen ve Verimlilik İçin: Conventional Commits Nedir?
Favicon
Good commit message V/S Bad commit message 🦾
Favicon
วิธี sign commit ด้วย GPG บน GitHub
Favicon
Git Together: Pro Tips for Commits and Branches
Favicon
Commit vs. Rollback: Database Transaction Essentials
Favicon
Sign Git Commits and Authenticate to GitHub with SSH Keys
Favicon
Developers Hate This One Weird Trick To Be Improve Their Craft
Favicon
Conventional Commits
Favicon
Cara memperbaiki commit git yang terlanjur commited
Favicon
Multiple SSH id
Favicon
💻 Semantic Commits
Favicon
Client side Git hooks 101
Favicon
How to write GIT commit messages
Favicon
The Power of Conventional Commits ✨✨
Favicon
What I've Learned About Git from Senior Colleagues (Part 2 - thoughful commit)
Favicon
GitHub Commits Color Scheme: Lets commit to commit.
Favicon
How do I make a Git commit in the past?

Featured ones: