Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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
Permission denied (publickey).

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

share|improve this question
up vote 18 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  id_rsa  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
IdentityFile ~/.ssh/yyy_id_rsa
User yyyuser

Host bit-xxxuser
IdentityFile ~/.ssh/id_rsa
User xxxuser

Host git-xxxuser
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.

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.

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

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


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.

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 '14 at 2:43

I configure ~/.ssh/config, like this:

Host gitlab-as-thuc  
    User git
    IdentityFile ~/.ssh/id_rsa.thuc
    IdentitiesOnly yes

then use custom hostname instead of real domain in git url:

git remote add thuc git@gitlab-as-thuc:your-repo.git  

For more detail please read here:

share|improve this answer

Your Answer


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.