How to setup private key ssh connection?

1

Lets say that to login to a remote address instead of a ssh login and password I have received rsa private and public keys. Is it safe to use it and how should I add them to the .ssh folder? manually appending the id_rsa files? I have only the authorized_keys there

koller23

Posted 2017-09-15T06:18:50.073

Reputation: 111

Question was closed 2017-10-05T15:35:25.340

Answers

0

Ssh private and public keys (asymmetric keys) works like that:

  • the private key should be only known (ie. stored) in a secure manner (eg. encrypted) in your client (local) machine. The default location for ssh keys are $HOME/.ssh/id_rsa. However you can have several keys stored in your local machine (eg. $HOME/.ssh/id_rsa_myotherkeypair). In that case you can tell ssh that you want use another key than the default by specifying the option -i

    ssh -i $HOME/.ssh/id_rsa_myotherkeypair USER@REMOTESERVER
    

    However a id_rsa* file shall by no mean contain multiple keys

  • the public key should be stored with your private key (unencrypted) in order not to lose it. It also must be advertised to your remote server (ie. associated with your user). There is several ways to achieve that:

    • append the content of the id_rsa.pub or id_rsa_myotherkeypair to the $HOME/.ssh/authorized_keys of your remote server.

    • execute the command ssh-copy-id on your local machine, that will do it for you :

      ssh-copy-id -i $HOME/.ssh/id_rsa_myotherkeypair USER@REMOTESERVER
      

vera

Posted 2017-09-15T06:18:50.073

Reputation: 760