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

AJAX - How To Retrieve JSON Response from PHP script

Hello Friends, This is my first tutorial post. Today I'll explain you how to retrieve JSON response via Ajax call. First we build a PHP script to send response in JSON format, then we will gather this response from an Ajax call through jQuery script. Let’s first create a PHP script  Create a PHP script, I’ll name it as “json_response.php” And add following code in it json_response.php <?php //set header for JSON response header("Content-Type: application/json"); //render array in JSON format echo json_encode(array('status' => 200, 'message' => 'Response from PHP script in JSON format.')); This is a basic example to send JSON response. PHP script will send response with status code and message. Now create a HTML file to fetch JSON response and add it in header tag. Create a HTML file, I’ll name it as “json_response.html” And add following code. json_response.html <html>           ...

JSON Tutorials : Getting Started

JSON is widely accepted text formatted structured data. JSON stands for " JavaScript Object Notation ". In general JSON can represent 1. Object of database record. 2. Object to represent a list of HTML elements. 3. Result of search query. 4. Response of an Ajax call. Here you can see JSON is used in many different areas and for many different scenarios. This means it has simple data structure. most of programming languages adopt it and it can flow easily from one connection to another. You can find JSON office definition here JSON Official Site . JSON is represented by two structural types, which includes two primitive types. Structural types Array : A sequential list of primitive data types between square brackets [ ] Object : Collection of key, value pair stored inside curly braces { }, where value would be primitive data type Primitive types : There are two primitive types key and value. " key " should be string and " value (data type)...

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...