Wednesday 6 September 2017

Set up SSH Public Key Authentication to connect to a remote host.

Host Server: host@example.co.in
Remote Server: remote@example.co.in

1. Login to the host server.

2. Keys will be located in the directory .ssh, if the .ssh folder is not present create at the user home.
      mkdir ~/.ssh

3. Change the permissions on our .ssh directory.
      chmod 700 ~/.ssh

4. Generate the keys using following commands.
      ssh-keygen

5. It will prompt you for the information it needs to generate the keys. Use all the default values (just press enters at every prompt).






















6. Your keys are now generated.
Go to .ssh folder, There should be 2 files in .ssh folder id_rsa and id_rsa.pub

7. Change the permissions of these files.
      chmod 700 ~/.ssh/id_rsa*

8. Now SSH to your remote server.
     ssh oracle@remote.example.co.in
     Enter your password and log in

9. Check if the .ssh directory exists on the server. If not then create at the user’s home.
      mkdir ~/.ssh

10. Change the permissions on our .ssh directory.
      chmod 700 ~/.ssh

11. Check if authorized_keys file is present in .ssh folder.
      If it doesn't, create it. You can use touch command to create an empty file.
           touch ~/.ssh/authorized_keys

12. Change the permissions on our authorized_keys file.
      chmod 700 ~/.ssh/authorized_keys

13. Logout from the remote server to return to the host server command prompt.
      Logout

14. Go to .ssh folder and copy contents of your local public key file (~/.ssh/id_rsa.pub, which you created earlier with ssh-keygen) into the file ~/.ssh/authorized_keys on remote server.
    vi id_rsa.pub
  • Copy content
  • Login to remote server in separate window
  • Go to .ssh folder 
           vi authorized_keys 
  • Paste the content and save the file

This completes the process of creating SSH configuration on both the servers.


Happy Learning!!!

No comments:

Post a Comment