Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot find id_rsa.pub in the unix server. Can I regenerate it? Id_sra (private key) exists

Tags:

ssh

public-key

What I want to do is to copy key to another host.

ssh-copy-id -i ~/.ssh/id_rsa user@host

I get error:

/usr/bin/ssh-copy-id: ERROR: failed to open ID file '[homedir].ssh/id_rsa.pub':

So there is no public key. So where is it? I tried to use command

sudo find / -name id_rsa.pub

but it only found one which I generated experimentally in my test directory. I tried sending the experimental from the test directory, but then it keeps infinitely asking paraphrase and does not send when I keep pasting.

So there is something wrong.

I could regenerate using

ssh-keygen -t rsa

but then it tries to use ~./.ssh directory

and wants to overwrite private id_rsa key. I am afraid this might brake something.

So how do I get my public key file?

like image 320
Dariux Avatar asked Oct 17 '14 09:10

Dariux


1 Answers

Just in case someone else comes here looking for an answer to the OP's question... and to directly answer that question (namely, how can you re-generate the .pub key in a situation where it is missing, and you only have the private key)...

Here is the answer:

Regenerating a .pub key from the private key

ssh-keygen -y -f ~/.ssh/id_rsa > ~/.ssh/id_rsa.pub

The -y option is the command instructing ssh-keygen to output your public key.

This will re-generate the .pub part of the pair. Just as the OP pointed out, if you simply generate a new pair, and replace the old private key, you will lose access to whatever servers you have already provided your public key to. Sure, you can go through the process of providing a new public key to those servers, but why go through that hassle if it can be easily avoided?

like image 131
inspirednz Avatar answered Oct 22 '22 01:10

inspirednz