Git logo

Git: Creating an SSH Key for BitBucket

Git: Basics Git'N Started

Today, we are starting with the basics of using Git and Version control: creating an SSH Key. For beginners, it can seem a little daunting or confusing, but I assure you, once you perform it a few times it will feel so simple.

Why Create an SSH Key?

Using an SSH Key registers your PC so you no longer need to use login credentials when performing any commands using git. Once registered, the SSH key is passed to the external server and verifies that you are the user of the account on their server, i.e. your Github or BitBucket account.

Step 1: Generate It

Open up Git Bash, cd ~ and type: ssh-keygen. From there, you will be asked to name your ssh key. It's optional, but if you have a few different accounts, it's worth giving it a unique name. It will also prompt you to generate a password, again, this is optional. For more information about using passwords when generating SSH keys, check out this Digital Ocean article.

To see your generated SSH key, type dir .ssh and it will output your files;

<username>@<PC_name> MINGW64 ~
$ dir .ssh
id_rsa  id_rsa.pub  known_hosts

Next, we're going to add the key to the agent. To do that, we need to start the agent by typing eval $(ssh-agent). After it outputs the PID, type ssh-add ~/add/<private_key>.

Step 2: Add the SSH Key to Bitbucket

Under your account settings, found on the lower left by clicking your avatar image and selecting settings. Find the SSH option on the left side-bar. Click Add SSH Key and give your key a name.

Now, back in your Git terminal, type cat ~/.ssh/<private_key>.pub, copy the output and paste it into the SSH field on Bitbucket. Hit Save.

Step 3: Verify your SSH Key

In the terminal, type ssh -T git@bitbucket.org:<username>/<repo>.git. The output will inform you if everything has completed successfully. Odds are, it will be just fine.

Step 4: Code

I hope you have enjoyed this quick explanation of creating SSH keys. Happy Hacking people!

{{ message }}

{{ 'Comments are closed.' | trans }}