How do I generate and add an SSH key?

Last updated by Adam West on July 08, 2020 15:10

Before you can start pushing to Codebase, you will need to add an SSH key. The steps below will walk you through generating an SSH key and then adding the public key to your Codebase account. The following guide primarily applies to Linux and MacOS systems, for a Windows guide, please click here.

Step 1: Check for existing SSH keys

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.

Step 2: Generate a new SSH key

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.

Step 3: Add your SSH key to Codebase

Run the following to copy the key to your clipboard.

$ pbcopy < ~/.ssh/id_rsa.pub
  1. Go to your My Profile page.

  2. Click "Add new SSH public key"

  3. Paste your key into the form and enter a description to assist you with identifying it in the future and finally click Add Public Key:

Step 4: Make sure everything works

You can test that you have uploaded the key by running the following:

## Using Git
$ ssh -T git@codebasehq.com # Attempts to SSH to Codebase as the Git user

## Using Mercurial
$ ssh -T hg@codebasehq.com # Attempts to SSH to Codebase as the Hg user

You may see the following warning, however this is perfectly normal, simply verify the fingerprint matches that shown below and type "yes".

The authenticity of host 'codebasehq.com (185.22.208.194)' can't be established. 
RSA key fingerprint is 2e:db:b6:22:f7:bd:48:f6:da:72:bf:59:d7:75:d7:4e. 
Are you sure you want to continue connecting (yes/no)? 

If you see a message similar to that below, you have successfully added your SSH key and may continue to fetch and upload your repositories into your Codebase account.

You've successfully uploaded your public key to Codebase and authenticated.  
Codebase does not, however, provide any direct SSH access. 
Please use your SCM client to interact with your repositories. 
The commands below may help you get started.      
* git remote add origin git@codebasehq.com:account/project/repo.git     
* git push origin master     
* hg push ssh://hg@codebasehq.com:account/project/repo.hg  
If you're having difficulties, please contact our friendly support team by emailing support@codebasehq.com.  
Authenticated with key #108647 

If you receive a message, similar to Permission denied (publickey,keyboard-interactive), this indicates your key has not been setup correctly.