In this comprehensive guide, we’ll walk you through the process of generating SSH keys, empowering you to enhance the security of your digital interactions. Table
Learn how to set up and manage multiple SSH keys for GitHub access. Follow this step-by-step guide to seamlessly handle multiple GitHub accounts with secure and organized SSH configurations.
Managing multiple SSH keys for different GitHub accounts can be a bit tricky, but it’s a common requirement for developers who work on various projects or contribute to both personal and professional repositories. This guide will walk you through the process of setting up and managing multiple SSH keys for GitHub access, ensuring a seamless and secure workflow.
Using multiple SSH keys is essential when you have:
First, generate SSH keys for each GitHub account. Open your terminal and use the ssh-keygen
command:
ssh-keygen -t ed25519 -C "your_email@example.com"
For a second GitHub account, you might name the key differently:
ssh-keygen -t ed25519 -C "your_other_email@example.com" -f ~/.ssh/id_ed25519_other
This command will generate two files: a private key (id_ed25519_other
) and a public key (id_ed25519_other.pub
).
Start the SSH agent and add the keys:
eval "$(ssh-agent -s)"
ssh-add ~/.ssh/id_ed25519
ssh-add ~/.ssh/id_ed25519_other
Log in to your GitHub accounts and add the public keys:
id_ed25519.pub
or id_ed25519_other.pub
) and paste it into the Key field.Photo by admingeek from Infotechys
Create or edit the ~/.ssh/config
file to specify which key to use for each GitHub account:
# Personal GitHub account
Host github.com-personal
HostName github.com
User git
IdentityFile ~/.ssh/id_ed25519
# Work GitHub account
Host github.com-work
HostName github.com
User git
IdentityFile ~/.ssh/id_ed25519_other
$ sudo
command output goes here
When cloning repositories, use the aliases defined in your SSH config file:
git clone git@github.com-personal:username/repo.git
git clone git@github.com-work:work-username/repo.git
If you need to use different Git configurations (e.g., user name and email) for each account, you can configure Git to use repository-specific settings.
Navigate to your repository and set the local configuration:
cd path/to/repo
git config user.name "Your Name"
git config user.email "your_email@example.com"
If you encounter a “Permission denied (publickey)” error, ensure that:
ssh-add -l
to list added keys).~/.ssh/config
file.Ensure that:
github.com-personal
or github.com-work
) when cloning or pushing to repositories.~/.ssh/config
file is correctly formatted and saved.By following these steps, you can efficiently manage multiple SSH keys for different GitHub accounts, ensuring secure and organized access to your repositories. This setup helps maintain a clear separation between personal and professional work, improving both security and workflow efficiency.
Did you find this article useful? Your feedback is invaluable to us! Please feel free to share your thoughts in the comments section below.
Related Posts
In this comprehensive guide, we’ll walk you through the process of generating SSH keys, empowering you to enhance the security of your digital interactions. Table
In this article, we will discuss SSH Weak Key Exchange Algorithms and how we can resolve them to enhance the security of SSH connections and
This article will guide you through the essential steps of creating, editing, backing up, and restoring a GPG key pair, empowering you with the knowledge