How to create SSH Key for GitHub and Bitbucket

SSH Key



This post demonstrate how to generate SSH private and public key with fundamental steps and assist you to add public key inside your GitHub and Bitbucket account.

But first why we need this SSH public key?

Whether you are working in the team or an individual and you want make any operations on secure GIT repository like clone or push your latest changes then you require to provide your credentials to help GIT to authenticate you and approve those operations.

But when you do so, you are asked to provide your username & passwordeach time on each operation.

It looks simple earlier, but later becomes a headache.

SSH connection helps us to authenticate using public and private keys, that we generate only once, later we don’t need to authenticateSSH will do this behalf of us.

But how does it work?


SSH authenticate you using an identity, your identity and this identity comprise combination of private, public key.

Private Key resides in your local machine and public key inside your GitHub or Bitbucket account.

When you perform any operation on Git repository which requires your identity or authentication, SSH combines these two keys, one from your laptop or PC (private key) and one from GIT repository (public key).

To use SSH, you need to install it first. I assumed that you had already installed it, if not. 
Then please visit http://www.openssh.com and install SSH to your local machine.

Generate private-public keys

Us following steps to generate private and public key, later copy public key and add it in your GitHub and Bitbucket account.

Open terminal and type following command

  ssh-keygen            

It will ask location for key files, hit Enter to select default location.

At that time it asked passphrase (password), you can or can't enter your password. It is best to add one.

It will ask re-passhprase

Once done, keys get generated and get saved inside provided location. 
Over here is sample output of ssh-keygen operation.

Next add your key to the ssh-agent.
  ssh-add ~/.ssh/id_rsa    

Later we need to add public key to GitHub and Bitbucket account. To do so, we need get. 
content of public key, this resides inside ~/.ssh path.

  cat ~/.ssh/id_rsa.pub     

Directly copy this key and visit GitHub or Bitbucket to add it into your account.

GitHub

Open a browser and log into your GitHub account.
  • Select setting icon from top right corner of menu bar.
  • Then select “SSH keys” from left side panel
  • Now add new public key by selecting “Add SSH key” button. It will open a panel to enter public key.
  • Add label for public key and then add copied public key inside key area.
  • Now finish this process by clicking "Add key" button.


That’s it. You done with GitHub

Bitbucket

Open a browser and log into your Bitbucket account.

  • Select Avatar->Manage Account from the application menu.
  • Under Security section Click SSH keys.
  • Then click Add key button. It will prompt a dialog to add public key.
  • Add label for public key and then add copied public key inside key area.
  • Now finish this process by clicking Add key button.


That’s it. You done with Bitbucket.

Conclusion


If you want to make your repository operation smooth then use SSH a convenient and secure tool and follow this guideline.

Comments

Post a Comment

Popular posts from this blog

AngularJs Tutorial: Getting Started

Abstract Factory design pattern analysis

AngularJs Tutorials : Bootstrap