How to properly copy private keys from remote servers to my localmachine so I can connect using ssh

13,250

First don't put your private key on the remote server. Any one compromising this server will have all access that you have.

Now that is out of the way. You have two options.

  1. Create a new private key on your new local machine. Then copy the public key (it comes with the private key, or can be generated from it). to the server. If goes in ~/.ssh/authorized_keys, one per line, so append it, don't overwrite the old one (or use ssh-copy-id).
  2. On the old local machine. Using putty, tell it to export your private-key in open-ssh format, then copy this to the new local machine (running openssh). It goes in directory ~/.ssh/ mine is in file id_rsa.
Share:
13,250

Related videos on Youtube

chille
Author by

chille

Updated on September 18, 2022

Comments

  • chille
    chille almost 2 years

    I have a multiple remote servers at Linode and Siteground with ssh connection, passphrase. I was using Windows and Putty to connect to my remote servers but now

    I started using Ubuntu 18.04 and I set up openssh-server but now when I'm trying ssh [email protected] I get error Permission Denied(Public key) so I'm guessing

    I should copy private keys from my remote server on my local machine but I'm not really sure where to place the keys exactly and how to add them so I can connect?

    • Kusalananda
      Kusalananda almost 6 years
      If you have set up everything correctly, you should definitely not have a single private key on the remote servers. Copy your private keys from the local machine that you used before. You also don't need to set up a local SSH server to connect to remote SSH servers.
    • chille
      chille almost 6 years
      I don't have private keys at remote server. I am not sure where on my ubuntu local machine I should copy this keys so I can connect to remote. I have .ssh folder and known_hosts file in it and that's all I currently have on my local machine.
    • Kusalananda
      Kusalananda almost 6 years
      So this question could potentially be about converting a PyTTY key file on Windows to OpenSSH format and copying it to Ubuntu?
  • chille
    chille almost 6 years
    This worked for me. First of all I didn't have a private key on my remote server, I didn't posted question properly - sorry for that. I generated key pairs on my local machine, copied public key and paste it on my remote server on authorized_keys file and then i just added my private key to ssh (ssh-add ~/.ssh/id_rsa) and that's it. Thank you all for your responses.
  • CpILL
    CpILL about 4 years
    This doesn't add the private key to the remote machine but the public key to the list of accepted keys
  • slm
    slm about 4 years
    @CpILL user's Q meant this, they asked the Q poorly. Added a disclaimer.