0

The situation is the following: I have a raspberry pi, with authentication off, and a ssh key with passphrase. The computer where I generated the ssh key doesn't work anymore, but I have backups of the id_rsa and id_rsa.pub files. I understand that simply copying these files to a new computer would not be very secure if this worked, but if my raspberry was not a physical device, but instead a cloud server, would I not be able to connect anymore? Everything would be lost? Can't I recover my access using the old keys and the passphrase? What is the good practice here? Always have a login authentication?

Edit:

To be more detailed about the steps I took and the error I'm getting, what I did was generation the keys on my old MacBook, and saved a backup of the d_rsa and id_rsa.pub files. I now have a new MacBook, where I copied the files to the .ssh folder. When I try to connect to my raspberry pi, running Debian, I get the following message:

@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ @ WARNING: UNPROTECTED PRIVATE KEY FILE! @ @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ Permissions 0644 for '/Users/caetano/.ssh/id_rsa' are too open. It is required that your private key files are NOT accessible by others. This private key will be ignored. Load key "/Users/caetano/.ssh/id_rsa": bad permissions

Permission denied (publickey).

2
  • 1
    You say "doesn't work anymore" is meaningless. What is the error message? What did you do?
    – Milliways
    Jan 5, 2021 at 21:51
  • I've edit my question to specify everything I did.
    – Caetano
    Jan 6, 2021 at 18:54

1 Answer 1

1

You say "I understand that simply copying these files to a new computer would not be very secure" - I don't know where you got this idea.

You can (and should) copy the public key to ~/.ssh/authorized_keys on any computer you trust.
My keys have been installed on my 9 Pi and all the other computers I use on my local network for ssh & ftp access

You should copy the private key to any of your computers you want to connect from. There is nothing to stop you having multiple private keys - I have several for different purposes, but use the same key on all my Pi.

The error message has the fix - key files should only be readable by the user i.e. rw permission for user caetano and read access for public keys but no access by others. If the keys are installed by the normal process ssh-copy-id this would be performed.

See https://www.ssh.com/ssh/copy-id#copy-the-key-to-a-server

You will need to set the permissions manually.

-rw------- 1 1000 1000 1199 2018-11-05 13:33 authorized_keys
-rw------- 1 1000 1000 1679 2018-11-12 13:37 id_rsa
-rw-r--r-- 1 1000 1000  399 2019-10-20 09:10 id_rsa.pub
-rw-r--r-- 1 1000 1000 3770 2020-11-26 17:00 known_hosts
2
  • I've copied the key to the .ssh folder and I'm getting the error Permissions 0644 for '/Users/caetano/.ssh/id_rsa' are too open. It is required that your private key files are NOT accessible by others. This private key will be ignored. Load key "/Users/caetano/.ssh/id_rsa": bad permissions
    – Caetano
    Jan 6, 2021 at 18:55
  • Changing the permissions of id_rsa.pub solved the issue. Thank you.
    – Caetano
    Jan 8, 2021 at 20:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.