DEV Community

Cover image for Adding SSH login to bitbucket
Visakh Vijayan
Visakh Vijayan

Posted on

Adding SSH login to bitbucket

Recently I noticed an easier way to login to bitbucket via SSH. Here is how to go about it. I use a Linux environment so the post is in accordance with that.

Open a terminal and type -

ssh-keygen
Enter fullscreen mode Exit fullscreen mode

This will create a private and public rsa key on your system. Just keep pressing enter to whatever question it throws you and in the end you will be able to see two files id_rsa and id_rsa.pub. The .pub means it's your public SSH key. This can be distributed. The other one you guard it with your life.

Now open bitbucket and go to Settings -> Security -> SSH Keys. Click on Add Key and give a title - (I usually give my machine's name) and paste your id_rsa.pub contents into the key textbox and Save.

Use this to open the public key file

cat ~/.ssh/id_rsa.pub
Enter fullscreen mode Exit fullscreen mode

Go to your repository source tab on bitbucket and click on Clone and select the SSH option. Copy the part that starts with git@bitbucket.org ...

Once done go to your code and open .git/config. You will be able to find a property -

[remote "origin"]
    url=<substiture the copied url here>
Enter fullscreen mode Exit fullscreen mode

You should be done. Try git pull, push or any other fancy commands you feel like and enjoy.

Happy coding!

Top comments (0)