After following this video in setting up your ssh-key with a custom algo like
id_custom
you might end up having error. the next step is add a configuration
To create or update an SSH config file (~/.ssh/config
), follow these steps:
Run this command to open the ~/.ssh/config
file using a text editor (e.g., nano
). If the file doesn’t exist, this command will create it:
nano ~/.ssh/config
Paste the following configuration into the file:
Host github.com
HostName github.com
User git
IdentityFile ~/.ssh/id_rsa
- Host: This is a nickname for the configuration.
github.com
is standard when configuring GitHub. - HostName: The actual hostname of the remote server (in this case,
github.com
). - User: The username for connecting to the host (GitHub uses
git
). - IdentityFile: The path to your private SSH key (e.g.,
~/.ssh/id_rsa
). Make sure this matches your actual key file.
If you’re using a different SSH key file (e.g., ~/.ssh/github_rsa
), update the IdentityFile
path accordingly.
- If you’re using
nano
, save the file by pressingCTRL + O
, thenEnter
. - Exit the editor by pressing
CTRL + X
.
Make sure the permissions for your ~/.ssh/config
file are secure:
chmod 600 ~/.ssh/config
Try connecting to GitHub again to make sure everything works:
ssh -T [email protected]
If it succeeds, you should see a message like:
Hi <username>! You've successfully authenticated, but GitHub does not provide shell access.
This confirms that the configuration is working correctly. If you encounter any errors, let me know!
How to Use Multiple GitHub Accounts on the Same Machine?Video
To use multiple GitHub accounts on the same machine, follow these steps:
Each GitHub account should have its own SSH key pair.
-
Generate a new SSH key for each account:
ssh-keygen -t rsa -b 4096 -C "[email protected]"
- When prompted, save the key under a specific name (e.g.,
~/.ssh/id_rsa_personal
for your personal account and~/.ssh/id_rsa_work
for your work account).
- When prompted, save the key under a specific name (e.g.,
-
Add the SSH keys to the SSH agent:
eval "$(ssh-agent -s)" ssh-add ~/.ssh/id_rsa_personal ssh-add ~/.ssh/id_rsa_work
-
Copy the SSH public key and add it to the corresponding GitHub account:
cat ~/.ssh/id_rsa_personal.pub cat ~/.ssh/id_rsa_work.pub
- Copy the output and add it as an SSH key in the settings of each GitHub account.
Edit your SSH config file (~/.ssh/config
) to map each SSH key to a specific GitHub account:
# Personal GitHub Account
Host github-personal
HostName github.com
User git
IdentityFile ~/.ssh/id_rsa_personal
# Work GitHub Account
Host github-work
HostName github.com
User git
IdentityFile ~/.ssh/id_rsa_work
When cloning or adding a remote repository, use the configured host instead of the default github.com
. For example:
- For your personal account:
git clone git@github-personal:username/repo.git
- For your work account:
git clone git@github-work:username/repo.git
You can set up specific user credentials for each repository so commits are linked to the right GitHub account.
-
Navigate to the repository folder:
cd path/to/repo
-
Set up the local user email and name:
git config user.email "[email protected]" git config user.name "Your Name"
or for your work repo:
git config user.email "[email protected]" git config user.name "Your Name"
If you need to switch the SSH key for an existing repository:
-
Open the repository's
.git/config
file. -
Update the
url
under[remote "origin"]
:- Change
github.com
to eithergithub-personal
orgithub-work
based on the account.
For example:
[remote "origin"] url = git@github-personal:username/repo.git
- Change
This setup allows you to work seamlessly with multiple GitHub accounts on the same machine.