How to setup SSH (keys) without passwords to VPS

It is possible to easily set your computer and vps up so that you can login without the need to supply the password on each occasion.

To do this you need to create an ssh key. Assuming that you are on windows you can use a program called puttygen which can be downloaded from PuttyGen

Once you have downloaded this program check that it is set to either SSH2-RSA or SSH2-DSA and if is simply click the 'Generate' link do as it says and move the mouse around to generate the key.

Once the key has completed alter the Key-Comment to something more memorable - 'mycomputer' if you want to.

Now what we need to do here is to save the privatekey to a location on your hard-drive - it will prompt you regarding not entering a passphrase but you can just ignore this - just save it as e.g. sshkey.ppk

Its also an idea to back up your publickey so you can use it again in the future.

Now that bits done we now need to simply get this key on to your server.

Using putty login to the server as you normally do using 'root' or your changed admin login username. And do the following

cd ~
mkdir .ssh
echo "COPY CONTENTS OF KEY INTO HERE" >> ~/.ssh/authorizedkeys2


(Replace COPY CONTENTS OF KEY INTO HERE with the actual contents of the key file, please note the quotes ARE required.)


Log out of putty now and reopen it -

now from the menu options choose:
Connection->Data and enter your login name into the Auto-login box
and
Connection->SSH-Auth - click the browse button and locate the privatekey that you saved to your harddrive.

Now go back to the 'Session' menu item at the top - and put your IP in the Hostname box and in saved sessions box give it a name such as 'myvps' and click the save button

You should now see your saved session listed in the box - simply double clicking this should now log you into your vps without any need for a password (the first time you will be asked if you want to add the key to the cache)

Article ID: 157, Created On: 3/18/2009, Modified: 9/15/2010