Setting up SSH access to your Bitbucket account

Let’s consider a scenario where you are in your virtual machine and you are up to setting up your project. Your project currently lies in your bitbucket or any other git remote server. Using your credentials directly albeit seems a simple solution, a recommended and a secure way to access your repo is — drum rolls — enabling SSH access. Well, you could follow this to manage multiple Bitbucket or Github or Gitlab accounts.

Step 1: Generating a SSH Key

First let’s generate a key pair using ssh-keygen.

$ ssh-keygen -f ~/.ssh/rsa_bitbucket

By default your shh keys are stored in .ssh dir. I’m going with rsa_bitbucket for my file name you can stick to anything you want.

Next you would be asked to enter a passhrase. You can set one or leave it empty.

Complete output after this step should be something like the following:

$ ssh-keygen -f ~/.ssh/rsa_bitbucket
Generating public/private rsa key pair.
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /Users/sarankumar/.ssh/rsa_bitbucket.
Your public key has been saved in /Users/sarankumar/.ssh/rsa_bitbucket.pub.
The key fingerprint is:
SHA256:J39KhXjr06ny196dOW704LGZ4/BX/QFWegj/BMtamgg sarankumar@Doc-Blr-L109.local
The key’s randomart image is:
+ — -[RSA 3072] — — +
| |
| . . . |
| + * |
| E . . X o |
| S = B = .|
| * * o+o|
| +.o+.*=|
| .o.o+oB+B|
| o=+ o**+|
+ — — [SHA256] — — -+

Step 2: Add the key to SSH agent

Now that we have our ssh key generated we need to add it to our ssh agent.

Run,

$ eval $(ssh-agent)

This starts the SSH agent. Next to add out key to it, run

$ sudo ssh-add ~/.ssh/rsa_bitbucket
Identity added: /Users/sarankumar/.ssh/rsa_bitbucket (your device name)

Step 4: Adding the key to Bitbucket

Run the following command to copy the public key. And paste it in your bitbucket account. You can find this setting under Personal Settings > Security > SSH Keys.

$ cat ~/.ssh/rsa_bitbucket.pub | pbcopy < .

And BOOM you are good to go. Bonus tip, to check everything is working fine run,

$ ssh -vT git@bitbucket.org

That’s it, you are logged in to your Bitbucket account🍭

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store