loading...
Cover image for Configuring SSH Key for Bitbucket repositories

Configuring SSH Key for Bitbucket repositories

jorge_rockr profile image Jorge Ramón ・2 min read

It's pretty common that beginner developers get used to do the same thing over and over again, more specific, log into bitbucket server every pull and push, because... why not?.

Well, if you are doing it so, let me tell you that:

  1. You are wasting your precious time
  2. You are typing more that should be
  3. Please, stop doing that

So, let's get started!

Step 0: Install Git

I'm assuming you did this before 😒, doesn't matter if you are using Windows or Linux but if you are using Windows... PLEASE INSTALL GIT BASH.

Step 1: Create the file id_rsa.pub

Open your terminal (or Git Bash if you are using Windows) and type:

ssh-keygen -t rsa -b 4096 -C "your@email.com"

If you did it well then this should appear:

Generating public/private rsa key pair.
Enter file in which to save the key (/home/<your-user>/.ssh/id_rsa):

From this point you need to do just one thing... PRESS ENTER OVER AND OVER AGAIN to get this:

Created directory '/home/<your-user>/.ssh'.
Enter passphrase (empty for no passphrase): 
Enter same passphrase again: 
Your identification has been saved in /home/<your-user>/.ssh/id_rsa.
Your public key has been saved in /home/<your-user>/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:lXhYzNtK37chmNGsV5/278yr6LrWuUygcYvqklcdtzI my.email@gmail.com
The key's randomart image is:
+---[RSA 4096]----+
|         o.      |
|         +o.     |
|        o +oo    |
|         +oo.o . |
|       .S+oo*.. o|
|       .=E+=.o.+o|
|    . .o .+.o o.+|
|   o ..  .oo.  +.|
|    +o  .o+=...oB|
+----[SHA256]-----+

A file called id_rsa.pub was created.

Step 2: Check if you did it well

Just to be sure, let's see the content of the file with this command (applies for Windows users too):

cat ~/.ssh/id_rsa.pub

And you should see something like this:

ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAACAQDKk+oiraZNtLEOsnoipb2vQneDKEu/KRjkimYucyrISkELCIqudGDhPyOxsKDIh61+tkoufJ6l0i9OCWVF/ckF2b8EZmqDLPIQR0x3Idg8vkmYS+aD/DdeUDrCYOR0rWXrCAdOOMJrkuoN0z+rFEGHW+Lkx8JqIwUm237RVOnJy9g8XG9bpRjjNZGLvhVIR0rmNtJ3NdEHZTrXmkookIU1/XTr/WVn6W7L695yyIYonNGczDrhAmnqYFm6HQabb4NTUm37PiZRxbkiJLjAo44AMM+4FhUrYN9FJkfgSqa3yJAYAGwFxRarw0JiG5yocXMLfP3kkcpfXrSxB2hz4D3U3Mw814tcUlLYQtcJN0kzO5qSUWfXeedZsmQw5p2zwlcrLcXeIvOleupvK+H+r7CW2Efvq/GZtZUytwgO1J2uOrs8RBZMWTYjz1qXOmC03V7Kft3Mcn9udGmuDB9nWuPJi8wl9UyHT/hUpJi4g/n9hazulnToM9mBOi82x2aMvcbnapsPk5dMFmh3lZylAs/szQwYbR05Qu6UXZxoZXWsoZds4O/RrXIsyViw6FKLvO2diJlDNuDu9fg4FK5kbOEktqqi6h3pY8QtJEM7I1iiKUeZVzinswn0Xh7bwEOduT+aZ79J99MV8pav6EsBEEIi+9qFbcuzIMTKrqcUYfOWOw== my.email@gmail.com

That's your SSH key.

Step 3: Configure your SSH key into Bitbucket (similar applies to Github)

Log into Bitbucket and search your user icon:

#1 Search your user icon

Now click on Bitbucket settings option:

Click that option

Now click on SSH keys option:

Click that option

Now press the Add key button. If you previously configured a SSH key then it will be listed (like mine):

Press the button

For last, enter whatever name you'd like and paste the content you saw on step 2:

Press save

And that's all. Very easy isn't?

Step 4: Clone your repository using SSH protocol

It's time to proof that you did it well, so create or go to any repository and press Clone button. You should see the SSH option selected:

Press clone button

For last, just clone your repository and be happy 😁:

Be happy

Posted on Sep 19 '18 by:

jorge_rockr profile

Jorge Ramón

@jorge_rockr

Full Stack Developer at @Globant. Javascript is all that you need.

Discussion

markdown guide
 

Thank you! Huge help, I've been struggling with this all morning.

 

Hi, great article, but i have tried using SSH, but can't get it to work

getting an error:
ssh: connect to host bitbucket.org port 22: Network is unreachable

 

Hi! Thanks for your feedback.

That error happens when you try to clone a repository?

Are you sure that you have internet access? (Try ping command to check)