Menu

Generating SSH Keys on Ubuntu (AWS EC2) for Github

I just wanted to create ssh key to connect to Github.

I tried to do it as described in the Github help. See link here. But this did not worked for me. I had to add some more steps. I will copy paste it a little from the github help and modify the stuff that worked for me.

Step 1: Check for SSH keys

Have an existing keypair you’d like to use? You can skip to Step 4.

First, we need to check for existing ssh keys on your computer. Open up Terminal and run:

1

2

cd~/.ssh

# Checks to see if there is a directory named ".ssh" in your user directory

If it says “No such file or directory” skip to step 3. Otherwise continue to step 2.

Step 2: Backup and remove existing SSH keys

Since there is already an SSH directory you’ll want to back the old one up and remove it:

1

2

3

4

5

6

7

8

9

10

11

12

ls

# Lists all the subdirectories in the current directory

config id_rsa id_rsa.pub known_hosts

mkdir key_backup

# Makes a subdirectory called "key_backup" in the current directory

cp id_rsa*key_backup

# Copies the id_rsa keypair into key_backup

rm id_rsa*

# Deletes the id_rsa keypair

Step 3: 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.

Step 5: Set owner of the file

set the ubuntu as owner for the files

1

2

sudo chown ubuntu id_rsa

sudo chown ubuntu id_rsa.pub

Step 6: Test everything out

To make sure everything is working you’ll now SSH to GitHub. When you do this, you will be asked to authenticate this action using your password, which for this purpose is the passphrase you created earlier. Don’t change the git@github.com part. That’s supposed to be there.

1

2

ssh-vT git@github.com

# Attempts to ssh to github

You may see this warning:

1

2

3

# The authenticity of host 'github.com (207.97.227.239)' can't be established.