SSH Key Set-up for Pre-existing KeyΒΆ

Here are the steps for SSH key set-up for pre-existing keys:

  1. Place the existing key under ~/.ssh/ folder on first Master VM.

  2. Create .ssh directory on remote machine using:

    ssh -i ~/.ssh/mykey.pem <user>@<remote_machine> mkdir -p .ssh
    
  3. Upload generated public keys to remote machine using:

    cat ~/.ssh/my_publickey.pub | ssh -i ~/.ssh/mykey.pem <user>@<remote_machine> 'cat >> .ssh/authorized_keys'
    
  4. Set permissions on remote machine using:

    ssh -i ~/.ssh/mykey.pem <user>@<remote_machine> "chmod 700 .ssh; chmod 640 .ssh/authorized_keys"