Putty is one of top ssh client available on Windows. It is lightweight and just run out of the box. Doesn’t need installation and connect you to ssh server securely. But if you need to use automatic login or use your private rsa key to login to your ssh server you need an extra tips to do that.
Image Courtesy: Ryan Werber
Generate Public/Private Key
To generate public/private key in Putty you need to download a tools called puttygen from Putty download page. And follow the following instructions:
- Open puttygen.exe
- Select Key > Generate Key Pair Menu
- Follow the instruction to move your mouse into the blank area. See the image below:
- Save the public key as id_rsa.pub
- Save the private key as id_rsa.ppk
- That’s it.
Adding Public Key into .authorized_key
To enable automatic login to your ssh server, you need to upload your id_rsa.pub content into your ssh server under .ssh/.authorized_keys. Follow the following step by step instructions below:
- Connect to your server using putty normally
- If you are connected successfully and you will be in your home directory
- If no .ssh folder under your home folder (usually /home/), create one using:
mkdir .ssh
- Create .authorized_keys with this command:
touch .ssh/authorized_keys cd .ssh
- Open .authorized_keys with vim:
vim authorized_keys
- Open id_rsa.pub in your local directory with notepad, and copy all the content.
- Paste it in authorized_keys file and save it.
Automatic Login Using pageant
After you generate public/private key using puttygen.exe, now you need to use pageant to automatically use your private key to login with Putty. Otherwise you need to add it manually under Connection > SSH > Auth in Putty for everytime you connect, wasting of time. The solution is use pageant and you add your private key.
See the following instructions:
- Download pageant.exe
- Run it, and it will be running in your taskbar
- Right Click it and choose “Add Key”
- Choose the id_rsa.ppk
- Now you can open new session and login without use your password anymore.
Now you need to add your id_rsa.pub key to all your ssh server to able to login without a password with putty. And remember to hide your id_rsa.ppk in your safest folder, because if somebody get this file, they can login to your server easily as well.