Thursday, January 12, 2012

Setting up RSA Key Authentication from Windows to Linux

How To Set up Key Authentication on a Windows PC connecting to a Linux Server

First of all, let's get PuTTY for windows: http://www.chiark.greenend.org.uk/~sgtatham/putty/download.html

Make sure you download PuTTY, PFTP, PuTTYgen, Peagent and plink.

Save them to a folder C:\PuTTY\

This tutorial assumes you've connected to your Linux Server using SSH so you know sshd is installed and running and that you have access.

Launch PuTTY and login using your username and password

Once logged into the Linux Server you'll need to generate your public and private keys

In PuTTY create the directory in your home share for your public key

mkdir ~/.ssh
chmod 700 ~/.ssh
cd ~/.ssh
ssh-keygen -t rsa


Enter the location for the key pair files. We want to put it in our .ssh folder that we just created.

~/.ssh/id_rsa
cat id_rsa.pub >> ~/.ssh/authorized_keys2
chmod 600 ~/.ssh/authorized_keys2

At this point we want to copy our private key to our Windows PC. You can use PFTP or FileZilla works nicely for those that are used to a GUI. Save it in the C:\PuTTY\ folder or a secure location that you can easily find.

Connect with FileZilla to your Linux Server and copy your id_rsa.ppk (Your Private Key) to your local Windows PC.

Now you'll need to convert your .ppk file from the OpenSSH format to PuTTY's .ppk format. 

Launch PuTTYgen and from the "Conversions" menu, select the "Import key" option. Select your key and follow the prompts to enter your pass phrase if you created one. Save your new private key to C:\PuTTY\.

Now launch PuTTY, input the IP or hostname for the Linux Server. In the left hand column select the SSH option and in the AUTH section browse to the PuTTY ppk file for your Private Key. 

You should now be able to connect to your Linux Server using Key Authentication. 

No comments: