Putty Public Key Authentication

 

On Client Machine

Generate Private/Public Key Pair with PUTTYGEN.EXE

* Change directory to PuTTY installation directory, e.g. C:\prog\PuTTY
* Double click PUTTYGEN.EXE
* Select:
– Type of key to generate: SSH-2 RSA
– Number of bits in a generated key: 2048
* Click Generate
* Move the mouse around in the Key area
* Private/public key pair is generated:

Save Private Key

* Enter:
– Key passphrase:
– Confirm passphrase:
* Click Save private key and save private key to a local directory, e.g. C:\Users\jimmy\MyPuTTYPrivateKey.ppk

* You don’t need to save public key for this exercise

On SSH Server Machine

Setup authorized_keys2 File

* SSH into server machine with password authentication for now
* Change directory to user’s home directory
* Make a new directory named .ssh if it does not exist already:
* Change directory to .ssh directory:
* Check /etc/ssh/sshd_config file for the name of the AuthorizedKeysFile, e.g.

AuthorizedKeysFile .ssh/authorized_keys2

* Open or create a file named authorized_keys2:

cd ~
mkdir .ssh
chmod 700 .ssh
cd ~/.ssh
vi authorized_keys2

* Copy and paste the public key from PuTTY Key Generator window

to the authorized_keys2 file:

* Alternatively, you can convert SSH2 public key to OpenSSH key before appending to authorized_keys2 with following command:

ssh-keygen -i -f ~/.ssh/ssh2_key.pub >> ~/.ssh/authorized_keys2

* chmod for authorized_keys2

chmod 600 authorized_keys2

Configure Private Key for PuTTY Session

Add Private key to PuTTY SSH Authentication Agent

* Go to the PuTTY program directory
* Double click PAGEANT.EXE file
– Agent is open up in the task panel

* Right click the agent icon in the task panel and select Add Key

* Browse to myPuTTYPrivateKey.ppk file and click Open
* Enter passphase for key and click OK:

Start PuTTY Session

* Open PuTTY
* Load a saved session
* Select Connection > SSH > Auth
* Set Private key file for authentication to private key file: C:\Users\Jimmy\MyPrivateKey.ppk

* Set Host Name in the format: user@server, e.g. oracle@dbserver

* Save the session again
* Click Open to start the session. You should be able to login without password.

This entry was posted in ssh and tagged , . Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *


*

This site uses Akismet to reduce spam. Learn how your comment data is processed.