Sunday, 6 June 2021

Copy public key to remote server


// on local server with ssh enabled, and public key / private key generated

// If not generate pub-private key first

Linux and MacOS X

  1. Open a terminal window. At the shell prompt, type the following command:

    ssh-keygen -t rsa
    
  2. The ssh-keygen program will prompt you for the location of the key file. Press Return to accept the defaults. You can optionally specify a passphrase to protect your key material. Press Return to omit the passphrase. The output of the program will look similar to this:

    Enter file in which to save the key (/Users/tony/.ssh/id_rsa):
    Created directory '/Users/tony/.ssh'.
    Enter passphrase (empty for no passphrase):
    Enter same passphrase again:
    Your identification has been saved in /Users/tony/.ssh/id_rsa.
    Your public key has been saved in /Users/tony/.ssh/id_rsa.pub.


// Copy generated public key(/.ssh/id_rsa.pub.) to remote server

3 . ssh-copy-id user@remoteHost


OR

1) on local server, retrieve public key

cat ~/.ssh/id_rsa.pub
// public key will start with ssh-rsa 

2) manually go to remote server 

vim ~/.ssh/authorized_keys

 and paste this key from step 1



https://docs.rightscale.com/faq/How_Do_I_Generate_My_Own_SSH_Key_Pair.html

https://linuxhandbook.com/add-ssh-public-key-to-server/ 

https://askubuntu.com/questions/46424/how-do-i-add-ssh-keys-to-authorized-keys-file

No comments:

Post a Comment