You may have been using SSH key to login, retrieve code on BitBucket.org for some account. Perhaps, then you wished to do the same for another account but when adding your public ssh key for the another account you got the error – Someone has already registered that SSH key. This post is how to automatically push, pull and connect to any of Repo’s from your machine on any of the accounts hosted by BitBucket.org
We found our solution to this limitation in mercurial extension – mercurial_keyring. In this post we will cover how to install the extensions and then how to configure mercurial to remember credentials for different repos on different accounts in BitBucket.org
About The Extension – mercurial_keyring
Here description from http://pypi.python.org/:
mercurial_keyring is a Mercurial extension used to securely save HTTP and SMTP authentication passwords in password databases (Gnome Keyring, KDE KWallet, OSXKeyChain, specific solutions for Win32 and command line). This extension uses and wraps services of thekeyring library.
The extension prompts for the password on the first pull/push (in case of HTTP) or first email (in case of SMTP), just like it is done by default, but saves the password. On successive runs it checks for the username in .hg/hgrc, then for suitable password in the password database, and uses those credentials (if found).
In case password turns out to be incorrect (either because it was invalid, or because it was changed on the server) or missing it just prompts the user again.
Passwords are identified by the combination of username and remote address, so they can be reused between repositories if they access the same remote repository (or the same SMTP server).
Installing The Extensions – mercurial_keyring
1. Clone The Project
>hg clone https://bitbucket.org/Mekk/mercurial_keyring
2. Configure Extension. To do so update .hgrc config file ‘extensions’ section in your home directory(the global mercurial config) as following:
[extensions] mercurial_keyring = /path_To_dir_cloned_step_1/mercurial_keyking.py
This will enable the extension – mercurial_keyring for mercurial hg
Configuring For Multiple BitBucket Accounts
In the global mercurial config (.hgrc in home directory) you can config each Repo on different BitBucket accounts as follows:
[auth] minnehaha.prefix = https://firstname.lastname@example.org/minnehahalofts minnehaha.username = minnehahalofts minnehaha.schemes = http https kapasoft.prefix = https://email@example.com/kapasoft kapasoft.username = kapasoft kapasoft.shcemes = http https
In above, we created two aliases – minnehaha and kapasoft each referencing two different BitBucket accounts. The good thing this works for clone command as well, so now i can quickly clone three different repos on two different BitBucket accounts:
>hg clone https://firstname.lastname@example.org/minnehahalofts/repo1 http authorization required realm: Bitbucket.org HTTP user: minnehahalofts password:xxxx >hg clone https://email@example.com/kapasoft/repo2 http authorization required realm: Bitbucket.org HTTP user: kapasoft password:xxxx >hg clone https://firstname.lastname@example.org/kapasoft/repo3 http authorization required realm: Bitbucket.org HTTP user: kapasoft password:xxxx
Each time it will prompt for password for the appropriate username. It is only for the first time since we connecting for the first time. Afterwards, the extension save the passwords making it very convenient to push, pull or any other way connect to the Repos
1. ‘abort: No module named keyring!’
Issue: keyring library missing on your machine. To install, run ‘easy_install keyring’ from command line