Skip to main content

How to create an SSH key for GitHub and Bitbucket

SSH Key



This post will show you how to generate SSH private and public keys step by step, as well as how to add public keys to your GitHub and Bitbucket accounts.

But first, why do we require this SSH public key?

If you want to do any work on a secure GIT repository, such as cloning or pushing your latest changes, you will need to provide your credentials to help GIT authenticate you and approve those operations, whether you are working in a team or as an individual.

However, each time you operate, you are prompted to enter your username and password.

It appears simple at first, but it quickly becomes a source of frustration.

To overcome the above problem, we can use the SSH protocol. SSH connections allow us to authenticate using public and private keys that we generate only once. after that, we don't need to authenticate because SSH will do so on our behalf.


But how does it work?

SSH authenticates you using an identity, and this identity is made up of a combination of private and public keys.

A private key is stored on your local machine, while a public key is stored on your GitHub or Bitbucket account.
When you perform any operation on a Git repository that requires your authentication, SSH combines these two keys.


To use SSH, you must first install it. Please follow the steps given in the following link.
http://www.openssh.com


Generate private-public keys

Follow the steps below to generate a private and public key.
Open a terminal and enter the following command.


  ssh-keygen            

It will request the location of key files. To select the default location, press Enter.

It will then request a passphrase (password). You can omit it, but it is preferable to include one.

After that, it will prompt you to reenter your password for confirmation.

After that, keys will be generated and saved in the specified location.

Here's an example of the ssh-keygen operation's output.





Next, add your key to the ssh-agent.

  ssh-add ~/.ssh/id_rsa    

Later, you need to add the public key to your GitHub and Bitbucket accounts. To do so, we need to get content of the public key. This resides inside ~/.ssh path.


  cat ~/.ssh/id_rsa.pub     

Copy this key and go to GitHub or Bitbucket to add it to your account.

GitHub

Log in to your GitHub account in a browser.

  • Select the setting icon from the menu bar's top right corner.
  • Then select "SSH keys" from the left side panel.
  • Now add the new public key by selecting the "Add SSH key" button. It will open a panel to enter a public key.
  • Add a label for the public key and then add the copied public key inside the key area.
  • Now finish this process by clicking the "Add key" button.
That’s it. The configuration for GitHub is done.

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.

This will complete the configuration for Bitbucket.

Conclusion

If you want your repository to run smoothly, use SSH with public and private key configuration.

Comments

Post a Comment

Subscribe for latest tutorial updates

* indicates required

Popular posts from this blog

JAX-RS Tutorials: REST API using Java

JAX-RS is API specification   for RESTful web services using Java. RESTful web services is implementation of REST ( Representational State Transfer ) which is architectural design for distributed system or in general we can say JAX-RS  is a set of APIs to develop REST service.   This is a brief introduction about REST and JAX-RS. You can find more information on REST on Wiki and JAX-RS Official Site. What is REST? Representational state transfer is an abstraction of the architecture of the World Wide Web. More precisely, REST is an architectural style consisting of a coordinated set of architectural constraints (source  Wikipedia ) As JAX-RS is only a specification, we need to use it's implemented library to create RESTful web service. Following are such list of libraries Apache CXF , an open source  Web service  framework. Jersey , the reference implementation from  Sun  (now  Ora...

Twig Tutorials: Install and Configure

In this tutorial, we'll look at how to install Twig within your PHP project and thereafter configure it so that we can create and use a Twig template inside our PHP web application. Later on, we'll see a simple Twig template example that displays a "Welcome to Twig template" message. Let's take it one step at a time. Install The Twig template can be installed using Composer, Git, or PEAR. In this tutorial, we will use Composer to install Twig. To do so, we'll need to make a "composer.json" file. { "require" : { "twig/twig" : "1.*" } } From the console, run the following command . $ php composer.phar install This command will install Twig library. Configuration To use the Twig template, we should first configure it. To achieve this, we will write an index.php file which will configure the Twig autoloader and generate the Twig environment. We will render the Twig temp...

Preload Images Using Javascript

Preload Image is technique which helps browser to render images with minimum delay. Today we will see example of image gallery. Gallery contain 5 images which load images one after another whenever user clicks next and back button. This is a basic image gallery scenario which is used in all possible website, then why we need preloaded images for this gallery? Now a day’s most of website becoming faster and user expectation is increasing. Suppose your website doesn’t use preload image technique for gallery and a user visits any image gallery from Google Plus or Facebook and visits your website gallery. Then that user always prefer those websites rather than yours. Why? Because your website load one image at a time. When user click on next button, then only gallery load image and user has wait till it get loaded. To avoid this situation gallery needs to download all images ...