DEV Community

Cover image for How to move your .ssh generated keys to a new laptop.
Wachira
Wachira

Posted on • Originally published at thedevnote.xyz

How to move your .ssh generated keys to a new laptop.

So I recently changed laptops, from being a Linux user for the past 2.5 years. I was running Parrot during that time, great os by the way if you are into cyber security stuff or just another full-stack developer like me.

I switch over to Mac, and all my ssh keys were in my previous laptop, they access all of my servers in Digital Ocean and AWS, to cloning and pushing to Github and so much more. I could not convince myself to update all servers with the new ssh keys and I had some issues with Github SSH cloning. So here are the steps I took, enabling me to move all my keys to my new laptop.

  • Copy over the ssh keys from your old laptop to the new one, they should be located in the ~/.ssh/ folder. You can use a flash drive or a cloud platform, whatever works for you.
  • Paste the files in your new laptop in the same directory.
  • Add the to your keychain
# for macos
ssh-add --apple-use-keychain ~/.ssh/id_rsa

# for linux
ssh-add -K ~/.ssh/id_rsa
Enter fullscreen mode Exit fullscreen mode
  • The Catch: If you do that you will get an error like this:
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@         WARNING: UNPROTECTED PRIVATE KEY FILE!          @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
Permissions 0664 for 'id_rsa' are too open.
It is required that your private key files are NOT accessible by others.
This private key will be ignored.
Enter fullscreen mode Exit fullscreen mode
  • To avoid this, run this command;
# this basically makes the keys read-writable by you
chmod 600 id_rsa
Enter fullscreen mode Exit fullscreen mode
  • Retry adding it to the keychain
# for macos
ssh-add --apple-use-keychain ~/.ssh/id_rsa

# for linux
ssh-add -K ~/.ssh/id_rsa
Enter fullscreen mode Exit fullscreen mode
  • The output should be:
Identity added: id_rsa (<ssh_name_will_appear_here)
Enter fullscreen mode Exit fullscreen mode

Top comments (1)

Collapse
 
angelo_tessaro_c3c6362dab profile image
Angelo Tessaro

I got this error still, after running the commands: Bad owner or permissions on /Users/angelotessaro/.ssh/config