Cannot Clone git Respository on Newly Create Ubuntu Server

Problem

Cannot clone git respository on newly create ubuntu server.

Solution

If you are getting an error similar to this

Warning: Permanently added 'codebasehq.com,00.00.000.000' (ECDSA) to the list of known hosts.
Permission denied (publickey)
fatal: Could not read from remote repository.

What you need to do is generate a public key on the server on this directory: ~/.ssh

How do I generate and add an SSH key?

Her are the steps to generate a public key:

1) Check for existing SSH keysPermalink Firstly we'll check your computer for any existing SSH keys. Open up Terminal and run:

ls ~/.ssh # Lists the files in your ~/.ssh directory

Check the returned list to see if you have a file called id_rsa.pub, if you do you can skip to step 3 otherwise continue on to step 2.

2) Generate a new SSH keyPermalink To generate a new SSH key, enter the code below. We want the default settings so when asked to enter a file in which to save the key, just press enter.

ssh-keygen 
## => Enter file in which to save the key (/Users/<b>your_username</b>/.ssh/id_rsa):  
## By default, this is fine. 

When asked to add a passphrase, it's strongly recommended to protect your key with a passphrase in case you lose it. Once you've entered your passphrase and confirmed it, press enter again to proceed to the next step.

3) Add your SSH key to CodebasePermalink Run the following to copy the key to your clipboard.

pbcopy < ~/.ssh/id_rsa.pub

Then add you public keys to your git repository.