Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

i have multiple ssh keys and i have also have account on bitbucket and github. how when ever i use pull it gives me error

:/var/www/proj$ git pull origin master
conq: repository access denied.
fatal: The remote end hung up unexpectedly

or if i ssh the bitbucket website it gives errors ass public key denied

:~$ ssh git@bitbucket.org
Permission denied (publickey).

how can i get this resolved and use different keys with different accounts.

share|improve this question

1 Answer 1

up vote 9 down vote accepted

This is all gathered from website and stackoverflow, hope this helps who are new to ssh

so you can have many ssh keys

~/.ssh$ ls
yyy_id_rsa  yyy_id_rsa.pub  id_rsa  id_rsa.pub  known_hosts

Note: we need to add then to the ssh-agent, probably id_rsa will be added so we need to add the other private key

~/.ssh$ ssh-add yyy_id_rsa

now we have added both ssh keys to ssh-agent

we have one for bitbucket and one for github

so we create a config file like this

~/.ssh$ nano config
Host bit-yyyuser bitbucket.org
Hostname bitbucket.org
IdentityFile ~/.ssh/yyy_id_rsa
User yyyuser

Host bit-xxxuser bitbucket.org
Hostname bitbucket.org
IdentityFile ~/.ssh/id_rsa
User xxxuser

Host git-xxxuser github.com
Hostname github.com
IdentityFile ~/.ssh/id_rsa
User xxxuser

Note: I am using 2 different keys for 2 different account on bitbucket and one for github.

Now we need to tell the git repository which host to use so that I will get that specific ssh key for that specific account

change git@bitbucket.orgyyyuser/yyyproject.git to git@bit-yyyuser:yyyuser/yyyproject.git

so in the project folder and add the remote url

/var/www/yyyproject$ git remote add bit git@bit-yyyuser:yyyuser/yyyproject.git

in other project

/var/www/xxxproject$ git remote add bitt git@bit-xxxuser:xxxuser/xxxproject.git

now you can use push and pull easily

:/var/www/yyyproject$ git pull bit master
From bit-yyyuser:yyyuser/yyyproject
 * branch            master     -> FETCH_HEAD
Already up-to-date.
:/var/www/yyyproject$

and another project

/var/www/xxxproject$ git push bitt ver1
To git@bit-xxxuser:xxxuser/xxxproject.git
 * branch            master     -> FETCH_HEAD
Already up-to-date.
:/var/www/xxxproject$ 

now I dont have the github project on the local machine so we need to clone the project but we need to make a little change to the url to clone

our url is like this

git@github.com:xxxuser/python.git

as we have to clone it with specific keys we just need to change the host name with the host we have defined

git@git-xxxuser:xxxuser/python.git

as defined in the config file

and now we can clone

:/var/www/us$ git clone git@git-xxxuser:xxxuser/python.git
Cloning into 'python'...
remote: Counting objects: 75, done.
remote: Compressing objects: 100% (42/42), done.
remote: Total 75 (delta 18), reused 62 (delta 8)
Receiving objects: 100% (75/75), 6.29 KiB, done.
Resolving deltas: 100% (18/18), done.
:/var/www/us$ 

we have identified different ssh keys for different host, one for git and one for bitbucket now the system knows which ssh keys to be used with which host.

Now we can easily pull, push.

share|improve this answer
    
What if my git URL is using https? Anyway to work on that? –  green Jun 4 at 2:43

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.