If you are working with multiple Github/Bitbucket accounts using ssh then you may face this problem, that you can’t use same ssh key on another account.
I face this problem everytime i reinstall operating system on my computer. And i have to google to find way to fix this problem. So i’m writing this to help me and you also.
So basically we will generate multiple ssh keys on single computer and merge those all ssh keys in Config file. And that config file will behave like bridge to all bitbucket/github account and deliver ssh key to those accounts accordingly.
ssh-keygen -t rsassh-add ~/.ssh/id_rsa
id_rsa
and id_rsa.pub
. 1st one is the secret key and second one is public key.Let say if you are working with 3 company account and 1 is your personal account. So add your default ssh key to your personal account. And create 3 new ssh keys for your 3 companies.
cd ~/.sshssh-keygen -t rsa -C "company_name1" -f "company_name1"ssh-add ~/.ssh/company_name1
cd ~/.sshssh-keygen -t rsa -C "company_name2" -f "company_name2"ssh-add ~/.ssh/company_name2
cd ~/.sshssh-keygen -t rsa -C "company_name3" -f "company_name3"ssh-add ~/.ssh/company_name3
config
file inside ~/.ssh
directory.nano ~/.ssh/config
This command will open config
file in command line editor and if this file doesn’t exist then it will create that file for you.
config
file, and modify according to your need.Host bitbucket.orgHostName bitbucket.orgIdentityFile ~/.ssh/id_rsaHost companyname1.bitbucket.orgHostName bitbucket.orgIdentityFile ~/.ssh/company_name1Host companyname2.bitbucket.orgHostName bitbucket.orgIdentityFile ~/.ssh/company_name2Host companyname3.bitbucket.orgHostName bitbucket.orgIdentityFile ~/.ssh/company_name3
Host github.comHostName github.comIdentityFile ~/.ssh/id_rsaHost companyname1.github.comHostName github.comIdentityFile ~/.ssh/company_name1Host companyname2.github.comHostName github.comIdentityFile ~/.ssh/company_name2Host companyname3.github.comHostName github.comIdentityFile ~/.ssh/company_name3
As you can see i’ve mapped company_name1
ssh key with account. Now add that company_name1.pub
’s ssh key on you companyname1.bitbucket.org
account.
I’m just giving dummy name, you can write anything which make sense to you and manageable for you.
Add key
and you are doneRepeat process for the next account, except this time copy the another company_name
Your personal project can be cloned same as before, but to clone project from any of the above company account you have to tweak then clone url.
Suppose if clone url of your company account looks like below,
git clone git@bitbucket.org:companyname/company-project.git
Then you have to modify this to look like below url (just add ssh key name which you have mapped in config file)
git clone git@**company_name.**bitbucket.org:companyName/company-project.git
You need to change only bold part.
Quick Links
Legal Stuff
Social Media