Reputation: 1
I have followed the tutorial to set SSH key for multiple github accounts.
But I keep getting the error
ssh: Could not resolve hostname github-psdtowordpresspro.com: Name or service not known
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
Steps followed:
id_rsa_psdtowordpresspro.pub
file in .ssh
directory. (Note that this folder was not there earlier. so I had to create one)Used the syntax ssh-keygen -t rsa -C "your-email-address"
Added the SSH key to my 2nd github account
Added the key
ssh-add ~/.ssh/id_rsa_COMPANY
Created the .config
file with the command
touch ~/.ssh/config vim config
This is the code I wrote in my .config
file
Host github-regipheirim
HostName github.com
User git
IdentityFile ~/.ssh/id_rsa_psdtowordpresspro
which is exactly how it was mentioned in the tutorial.
Then I added the remote origin as
git remote add origin [email protected]:regipheirim/regi.git
But then when I try to push it shows the error that "Hostname could not be resolved."
Here is a screenshot of
Git remote connection setting of second account
Project's .config
file
[core]
repositoryformatversion = 0
filemode = false
bare = false
logallrefupdates = true
symlinks = false
ignorecase = true
[remote "origin"]
url = git@github-regipheirim:regipheirim/regi.git
fetch = +refs/heads/*:refs/remotes/origin/*
[user]
name = regipheirim
email = [email protected]
ALSO TRIED (Based on suggestion from TJL in comment section)
git remote set-url origin [email protected]:regipheirim/regi.git
But then when I tried to push with
git push origin master
Again I get the error:
Permission denied (publickey).
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
So can anyone help me with what I am doing wrong here. I just spent the entire sunday figuring it out.
Upvotes: 0
Views: 293
Reputation: 5447
Solution for multiple accounts from that same service. In this case for Bitbucket.
~/.gitconfig
fileFor example for user JohnDoe
(with rsa key in ~/.ssh/id_rsa_john_1
) you should add
Host bitbucket.org:JohnDoe
User JohnDoe
HostName bitbucket.org
IdentityFile ~/.ssh/id_rsa_john_1
IdentitiesOnly yes
this username should also exist in URL which you are trying to clone via SSH, for example:
git clone [email protected]:JohnDoe/my_project.git
And when you have different account in that same service you can add it also:
Host bitbucket.org:RichardRoe
User RichardRoe
HostName bitbucket.org
IdentityFile ~/.ssh/id_rsa_richard_1
IdentitiesOnly yes
So in your file you will have TWO sections about bitbucket.org
.
Thanks to that you can use separate accounts (with different RSA keys).
eval $(ssh-agent)
ssh-add
for all of the accountsSo for this example it will be:
ssh-add -K ~/.ssh/id_rsa_john_1
and
ssh-add -K ~/.ssh/id_rsa_richard_1
Upvotes: 0
Reputation: 4945
You did not link to alias you have created in your config file
try:
git remote add origin git@github-regipheirim:regipheirim/regi.git
Upvotes: 1