← Back to front page

Bitbucket, Git and getting SSH working

About Bitbucket

Bitbucket is an excellent private Git repository from Atlassian; It is easy to use via Web interface, it has basic issue tracking system and it’s free up to 5 persons teams. It can be also linked easily to Atlassian JIRA project and issue tracking software.

In the past I have used Bitbucket for my own projects and I’ve been happy with the HTTPS authentication (using username & password). However, not long ago at the office when I set up Bitbucket-Bamboo-Jira-Maven-Nexus integration chain, I realized that automation requires SSH usage for Bitbucket access. In a nutshell BitBucket would not ask username/password anymore, instead it would use SSH to do the authentication automatically.

atlassian-bitbucketAtlassian provides really thorough 101 documentation setting SSH up, even for Windows users. Unfortunately, in this case of mine, the setup was to use standard Windows7(x64) command prompt and not the documented Git Bash shell.

As this was a new way for me to access BitBucket, I decided to use local Git repository <-> BitBucket connection to minimize all the moving parts. Honestly, I did not expect any problems as it was just a case of creating SSH connection.

About using public-private keys

From user point of view, using SSH identification is a simple deed; Generate public and private keys, store private key to your local machine and upload public key to Bitbucket. Once Bitbucket repository has been told to use keys for the authentication, then it is just a question of using SSH to do the connection (and no username-passwords questions are asked)

SSH issue emerges

As I had used key pairs whilst using Putty to connect our ALMDemo machines, I expected the prosedure to be much the same; generate keys, store keys to their wished locations and use SSH authentication agent.

This was my original cooking list:

1) Generation of the key pairs using PuttyGen.
2) Storing public key to Bitbucket via Manage Account / SSH keys
3) Changing Bitbucket repository to use SSH authentication
4) Use Pageant as Windows SSH authentication agent and add generated private key to its key list
5) Define remote git repository to use SSH authentication (git remote add origin git@bitbucket.org :< accountname>/< reponame>.git)
6) Clone the repository to local machine: git clone git@bitbucket.org:<username>/<gitrepo>.git

As a surprise, following error message was thrown.

Permission denied (publickey).
fatal: Could not read from remote repository.

SSH issue found and fixed

Issue looked like SSH agent was either not running or having proper key configuration. But these were set ok, and my other SSH connections worked ok, hence the confusion. It took moment or two to find the reason. Seems that when using Git in Windows command prompt, just using Pageant is not enough, one needs to have plink.exe as a companion.

The cooking list needed updating

6) Execute plink.exe
7) Define GIT_SSH=plink.exe as a Windows shell variable. Now git push/pull/etc commands are passing the SSH authorization
8) Clone the repository to local machine: git clone git@bitbucket.org:<username>/<gitrepo>.git       — Success! –

Now I had working SSH Git-Bitbucket connection in Windows7x64 command prompt and the original toolchain integration work was proceeding again. For future reference, I think the easiest and the fastest method would be to use Bash shell to set up all the keys and agents.

Leave a Reply

  • (will not be published)

Time limit is exhausted. Please reload CAPTCHA.

Please, leave us a message and we'll contact you.
You can also contact our Service Desk by phone +358 290 010 500 or email servicedesk@ambientia.fi.