Use another key in git

Today, 4th December 2022, Ukraine is still bravely fighting for democratic values, human rights and peace in whole world. Russians ruthlessly kill all civilians in Ukraine including childs and destroy their cities. We are uniting against Putinโ€™s invasion and violence, in support of the people in Ukraine. You can help by donating to Ukrainian's army.

Sometimes you may want to use git via ssh but with different ssh keys than other repositories. For example you may have corporative and hove bitbucket account, and bitbucket will not allow you use same pub key with both accounts.

So you need to run ssh-keygen and generate a new key (e.g. ~/.ssh/id_rsa_private), then add it to another bitbucket account.

But when you run git it will still use your default ssh key (if not configured another default will be ~/.ssh/id_rsa ).

But we can switch the default key using -i ssh option.

Change dir to the repo and run next:

echo export GIT_SSH_COMMAND=\"ssh -i ~/.ssh/id_rsa_private\" > ./gitize

Then before working with repo go to its dir and run

source gitize

You ready to go!

#git #ssh
Ivan Borshchov profile picture
Apr 16, 2017
by Ivan Borshchov
Did it help you?
Yes !

Best related