Before start I should say I have read a lot of topics (listed at the end of this post) about this issue but none is working for me or maybe I am missing something trivial in here.
At first I did clone the repository using HTTPS but then I switched to SSH following the docs from here. I did generate each of the SSH key and add them to the ssh-agent
following the docs from here.
In a few lines (fake data used, ~
means my home directory) this is what I've done:
$ ssh-keygen -t rsa -b 4096 -C "first@gmail.com"
Enter a file in which to save the key (~/.ssh/id_rsa): [Press enter]
Enter passphrase (empty for no passphrase): [Type a passphrase]
Enter same passphrase again: [Type passphrase again]
$ ssh-keygen -t rsa -b 4096 -C "second@gmail.com"
Enter a file in which to save the key (~/.ssh/id_rsa_second): [Press enter]
Enter passphrase (empty for no passphrase): [Type a passphrase]
Enter same passphrase again: [Type passphrase again]
$ eval "$(ssh-agent -s)"
Agent pid 12697
$ ssh-add ~/.ssh/id_rsa
Identity added: ~/.ssh/id_rsa (~/.ssh/id_rsa)
$ ssh-add ~/.ssh/id_rsa_second
Identity added: ~/.ssh/id_rsa_second (~/.ssh/id_rsa_second)
$ ssh-add -l
4096 SHA256:gb+Gn4SqiyAP5ABUsmX6Xz11RHTSvDsWgEE5P2R2VTE ~/.ssh/id_rsa (RSA)
4096 SHA256:yxWMompayDNtYjv5y+FfJl7OpQ5Qu90kPgdXXvx6DRA ~/.ssh/id_rsa_second (RSA)
The next step was create the ~/.ssh/config
file with the following content:
#first account
Host github.com-first
HostName github.com
User git
IdentityFile ~/.ssh/id_rsa
#second account
Host github.com-second
HostName github.com
User git
IdentityFile ~/.ssh/id_rsa_second
I stopped here and give this a try by adding the SSH pub key for id_rsa_second
to the repository where I want to use it (this doesn't need explanation). Next git pull
:
$ git pull
Bad owner or permissions on /home/rperez/.ssh/config
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
Then I tried the following:
Change the
.git/config
file to the following:[remote "origin"] url = git@github.com-second:repo/repo.git fetch = +refs/heads/*:refs/remotes/origin/*
But it didn't work and by this I mean I got exactly the same error as before.
What I am doing wrong? What I am missing?
What I have read:
- How to properly configure ssh keys to multiple remote accounts involving github and bitbucket?
- GitHub: Multiple account setup
- Multiple github accounts on the same computer?
- Quick Tip: How to Work with GitHub and Multiple Accounts
- Can't get Multiple SSH keys to work for multiple github accounts
- Multiple SSH Keys settings for different github account
Note: The title may seem confusing but it is correct because it is what I want to achieve I am just talking about one example but at the end I should be able to setup more than one account pointing to different repositories.