Monday, February 25, 2013

Setup SSH Private-Public Keys on Unix

  1. Generate Key-Pair using PuTTYGen
  2. Save private key to a safe place.  
  3. Massage the public key into openSSH format by doing the following
    •     Remove lirst 2 line
    •     Remove last line
    •     Join all lines into a single line
    •     Add 'ssh-rsa ' (remember the trailing space) at the start of the line


  4. Copy public key to unix ~/.ssh/authorized_keys file or append to the existing file content
  5. Use PuTTY to select the private key to ssh to the remote server

NOTE

If using Java library such as JSch to connect using private key, need to export private key into openSSH format first.  Load the private key just created into PuTTYGen and select convertion -> Export Openssh Key option.  Use the openssh format private key in Java code to connect to ssh.