Generate ssh in linux and make clone of bitbucket repository

Step 1

First we need to generate SSH key. It will create both private & public key you can run the command below from any directory

ssh-keygen

Step 2

When you run the command it will ask you the name of file you any filename you give it will create two files. For suppose you give file name mykey then it will create mykey & mykey.pub

mykey will be private key and mykey.pub will be the public key

After that it will ask for a passphrase you can give any passphrase also you can just press enter if you don’t want to give any passphrase.

Step 3

After that it will create both the keys also it will show you the directory in which the keys are saved for suppose /root/.ssh/id_rsa

id_rsa is default name but when you go into the root/.ssh then ls command will show you your files

Step 4

Go into the keys directory and copy the key into any other folder like below

cp mykey.pub /var/www/html

It will copy the public key to html folder then you can read the content of the key and the copy it.

Step 5

Now the content of the public key needs to be pasted on bitbucket

open bitbucket and select any repository and then go into REPOSITORY SETTINGS

There you will see “Access Keys” option. Click on that and add the public key and save it.

Step 6

Now we need to add the key into our ssh so that during cloning it authenticate the keys.

To start the agent run the following command.

eval `ssh-agent`

It will show something like Agent pid …

Now we need to run the below command

ssh-add ~/.ssh/mykey

After adding the key. Now you will be able to make a clone of your bitbucket repository.