1

I have two bitbucket accounts, one for my personal stuff and one for work. My personal one was working fine and the one I use at work also works fine; however I wanted to be able to connect to the work one from home but I am having trouble getting it to work.

My files are called:

## Unrelated ones I use for plan.io that still work

id_rsa
id_rsa.pub

## Personal one for bitbucket I just created because of seperation

homeid
homeid.pub

## Work one for bitbucket

workid
workid.pub

My config file is as:

Host home@bitbucket.org
 HostName bitbucket.org
 IdentityFile ~/.ssh/homeid


Host work@bitbucket.org
 HostName bitbucket.org
 IdentityFile ~/.ssh/workid

Now I got a little confused on how to do the cloning with the aliases, but tried:

git clone work@bitbucket.org:my-username/myrepo.git

But it fails with the error message:

Cloning into 'myrepo'...
Permission denied (publickey).
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

I have added the publick keys to the appropriate bitbucket accounts so not sure what I'm doing wrong here?

Brett
  • 19,449
  • 54
  • 157
  • 290

2 Answers2

2

Ok worked it out.

I was using the incorrect git clone address, the correct one being:

git clone git@workid:my-username/myrepo.git

...but also had to change my config file to the below to change the hosts:

Host homeid
 HostName bitbucket.org
 IdentityFile ~/.ssh/homeid


Host workid
 HostName bitbucket.org
 IdentityFile ~/.ssh/workid
Brett
  • 19,449
  • 54
  • 157
  • 290
1

Host home@bitbucket.org

The ssh_config Host directive doesn't accept the "username@" syntax. Use the Match directive instead:

Match user home host bitbucket.org
    HostName bitbucket.org
    IdentityFile ~/.ssh/homeid
...
Kenster
  • 23,465
  • 21
  • 80
  • 106