rsa public key No such file or directory?
Asked Answered
E

4

24

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

Exorcist answered 13/7, 2018 at 23:3 Comment(4)
SO is for programming questions, not questions about using or configuring Linux and its applications. Super User or Unix & Linux would be better places for questions like this.Molecular
You never did ssh-keygen to create the SSH key.Molecular
Thank you @Molecular I'll be sure to ask linux-y questions in those next time.Exorcist
In my case the file exists. But command fails as yours. I have just copied content of the file manually.Papal
C
35

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.

Cardcarrying answered 14/7, 2018 at 5:11 Comment(0)
H
6

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 "[email protected]"

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/

Helfrich answered 3/9, 2020 at 13:50 Comment(0)
B
1

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!)

Balladeer answered 3/2, 2022 at 7:7 Comment(1)
This helped me a lot. I'm using a macbook, going through the Rails/ruby install and got to the git/ssh key stage. I was in directory /users/me and kept getting this error. had a look at this answer and changed directory to /users/me/.ssh then it all worked and I could carry on with the guide.Loveliesbleeding
A
0

I simply added sudo before ssh-keygen and it worked.

sudo ssh-keygen

Agostino answered 21/11, 2023 at 14:35 Comment(1)
That is surprising. ssh-keygen by default writes the newly generated key to ~/.ssh/ in your home directory. ssh-keygen withour sudo should have worked. If it did not, either you did not post the full command or your home directory has files not owned by you (perhaps from using sudo when you should not have)Sheepshearing

© 2022 - 2025 — McMap. All rights reserved.