17

I'm trying to follow along the Upskillcourses.com web dev online course. In lesson 11 I'm supposed to link up cloud9 to github.

I'm trying to get the SSH key. But it's not working:

ec2-user:~/environment $ cat ~/.ssh/id_rsa.pub
cat: /home/ec2-user/.ssh/id_rsa.pub: No such file or directory

I've copied it exactly like the instructor did. I'll be honest in that I don't really know what I'm doing or how to fix. Seems like no one else is having this problem. Thanks for any help

Coder117
  • 801
  • 2
  • 9
  • 22
  • 3
    SO is for programming questions, not questions about using or configuring Linux and its applications. [su] or [unix.se] would be better places for questions like this. – Barmar Jul 13 '18 at 23:07
  • 2
    You never did `ssh-keygen` to create the SSH key. – Barmar Jul 13 '18 at 23:08
  • Thank you @Barmar I'll be sure to ask linux-y questions in those next time. – Coder117 Jul 13 '18 at 23:17

3 Answers3

30

Use ssh-keygen to create a default ssh key pair, for now without passphrase:

ssh-keygen -t rsa -C "MyEmailAddress" -f ~/.ssh/id_rsa -P ""

Then any ssh command will use by default that key.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
5

First, check for existing SSH Key using the following command:

ls -al ~/.ssh

Check the directory listing to see if you already have a public SSH key. By default, the filenames of the public keys are one of the following: id_xxxx.pub (ex: id_rsa.pub). If you don't have an existing public and private key pair, create one using this command:

ssh-keygen -t rsa -b 4096 -C "your_email@example.com"

This creates a new ssh key, using the provided email as a label. When you're prompted to "Enter a file in which to save the key," press Enter. This accepts the default file location. At the prompt, type a secure passphrase.

If you see an existing public and private key pair listed that you would like to use to connect to GitHub, or once you are done with the above key generation step, you can add your SSH key to the ssh-agent with the following commands:

eval "$(ssh-agent -s)"

ssh-add ~/.ssh/id_rsa (Add -K option, if on MAC OS, as it will add the passphrase in your keychain when you add an ssh key to the ssh-agent.)

Source: https://docs.github.com/

Nikita Jain
  • 669
  • 8
  • 11
0

This happened to me when I was simply in a directory other than the one where the SSH key was.

In order to fix this: you need to check the path to the directory where the SSH key was saved. Scroll up to where you created the key and you should see:

Your public key has been saved in /Users/userlocation/.ssh/id_rsa.pub

Now check your working directory:

pwd

If your working directory is different from the one that holds the SSH key, change the directory:

cd /Users/userlocation #find yours!

and then run the command (slightly changed):

cat .ssh/id_rsa.pub

This worked for me! (Remember to run ssh-keygen first!)

Anscandance
  • 113
  • 1
  • 1
  • 9