How to access a git repository using SSH?

Solution 1:

Setup Git

  1. Install it with sudo apt-get install git (see here)
  2. Configure Git (see here)

Implement SSH on GitHub/BitBucket

  1. Generate the SSH key with ssh-keygen -t rsa -b 4096 (see here)
  2. Copy the content of your public SSH key, it is the file id_rsa.pub by default
  3. Paste the content into your GitHub/BitBucket account on the SSH key section

Get the repo

Just clone it:

For more information managing a repo, take a look at the Git For Humans guide by Lucio Martinez.

GUI Tools

You can install git-gui which is a built-in GUI tool for commit.

For more options, take a look at the list on the official page.

Solution 2:

Step 1: Generate KEY

- cd   ~/.ssh

- ssh-keygen -t rsa -b 4096 -C "[email protected]"

NOTE - Keys need to be only readable by you:

chmod 400 ~/.ssh/id_rsa

If Keys need to be read-writable by you:

chmod 600 ~/.ssh/id_rsa

Step 2: Check the Contents and copy

- cat ~/.ssh/nameOfFile.pub | pbcopy

Step 3: Configure your SSH key into Bitbucket.org (similar applies to Github.com) GOTO settings => SSHKEY

- Add what you copied in Step 2 and give it a name

Step 4: Clone your repository using SSH protocol

- git clone [email protected]:{username}/repo.git

- git clone [email protected]:{username}/repo.git

This should work BUT

If you keep getting this error

[ Permission denied (publickey). fatal: Could not read from remote repository.

Please make sure you have the correct access rights

]

Follow this steps.

i. ssh -T [email protected] OR ssh -T [email protected] depending on which you are using { This will attempt to create a connection to Bitbucket OR Github Cloud ).

ii. If you do not see a message similar  to (logged in as username.). Go to the next step

iii. ssh-add ~/.ssh/identity (identity is whatever name you saved the file when generating a key)

iv. You will get this message (Identity added: /path to ssh file/.ssh/mywork ([email protected])
v. You can now clone your repository.