Tuesday 3 April 2018

How ssh work and generate ssh public key and private key?


Source: https://wiki.cdot.senecacollege.ca/wiki/OPS335_Lab_1


Generate key:


$ ssh-keygen


You will have id_rsa.pub and id_rsa

Send id_rsa.pub to server admin or paste into server you need to ssh.




Some reference link

Use SSH Keys with PuTTY on Windows

https://devops.profitbricks.com/tutorials/use-ssh-keys-with-putty-on-windows/

Copy Public Key to Server

The OpenSSH public key is located in the box under Key / Public key for pasting info OpenSSH authorized_keys file:. The public key begins with ssh-rsa followed by a string of characters.
  1. Highlight entire public key within the PuTTY Key Generator and copy the text.
  2. Launch PuTTY and log into the remote server with your existing user credentials.
  3. Use your preferred text editor to create and/or open the authorized_keys file:
    vi ~/.ssh/authorized_keys
  4. Paste the public key into the authorized_keys file.
    ssh-rsa AAAAB3NzaC1yc2EAAAABJQAAAQBp2eUlwvehXTD3xc7jek3y41n9fO0A+TyLqfd5ZAvuqrwNcR2K7UXPVVkFmTZBes3PNnab4UkbFCki23tP6jLzJx/MufHypXprSYF3x4RFh0ZoGtRkr/J8DBKE8UiZIPUeud0bQOXztvP+pVXT+HfSnLdN62lXTxLUp9EBZhe3Eb/5nwFaKNpFg1r5NLIpREU2H6fIepi9z28rbEjDj71Z+GOKDXqYWacpbzyIzcYVrsFq8uqOIEh7QAkR9H0k4lRhKNlIANyGADCMisGWwmIiPJUIRtWkrQjUOvQgrQjtPcofuxKaWaF5NqwKCc5FDVzsysaL5IM9/gij8837QN7z rsa-key-20141103
  5. Save the file and close the text editor.
  6. Adjust the permissions of the authorized_keys file so that the file does not allow group writable permissions.
    chmod 600 ~/.ssh/authorized_keys
  7. Logout of the remote server.

Connect to Server with Private Key

Now it is time to test SSH key authentication. The PuTTYgen tool can be closed and PuTTY launched again.
  1. Enter the remote server Host Name or IP address under Session.
  2. Navigate to Connection > SSH > Auth.
  3. Click Browse... under Authentication parameters / Private key file for authentication.
  4. Locate the id_rsa.ppk private key and click Open.
  5. Finally, click Open again to log into the remote server with key pair authentication.

 

 








No comments:

Post a Comment