Assumption:
- Client is windows and you will connect to server using putty
- Server is Ubuntu, I have tried this with Ubuntu 9.04 and it worked
- Root login is possible to server and have access to command line
Step 1: Prepare server for ssh server
1: apt-get install ssh
2: sudo apt-get install openssh-server
First line will install ssh on the server and second line with install openssh-server. If you are doing apt-get for the first time, make sure you have done apt-get update once so that server is updated for repositories.
Step 2: Create public - private keys
This will create public - private key on the server, keys can also be created using PUTTYGEN.EXE but in this post, we will do it on server. Once public - private keys are generated. they will be placed in ~/.ssh folder. Private key will be in id_rsa and public key will be id_rsa.pub. One server we need only public key.
Step 3: Download private key using PSFTP
Login to server using psftp, see help of putty (putty.chm) in case if you need help in using psftp. You will need to use open, lpwd, lcd, cd and get command of psftp
Step 4: Generate private key (of .ppk format) using PUTTYGEN.EXE
Open downloaded private key from server into puttygen.exe. You may need to type in passphrase if you have setup one while using ssh-keygen. Once key is open click on save private key button in puttygen.exe. This will generate .ppk file which can be later used with putty.exe
Step 5: Copy public key content to authorization key file on server
On server go to ~/.ssh using console where public and private key was generated, and execute following commands
1: cat id_rsa.pub >> ~/.ssh/authorized_keys
2: rm id_rsa.pub
3: rm id_rsa
This will create authorizaed_keys which server will use while authenticating user. And also delete public - private key file generated by ssh-keygen
Step 6: Make sure server accepts login using RSA keys
open /etc/ssh/sshd_config this is configuration file of ssh server. Make sure file has following configured
1: RSAAuthentication yes
2: PubkeyAuthentication yes
Use /etc/init.d/ssh reload to reload the changed configuration
Step 7: Try out login using RSA key file
Open putty.exe from client and type in host (name or ip) and supply .ppk file. On logon to server, it should ask user name, will also ask for passphrase if setup while generating key files.
Step 8: Disable plain text password authentication
open /etc/ssh/sshd_config file again and make sure you have following configuration entries to disable plain text password authentication
1: ChallengeResponseAuthentication no
2: PasswordAuthentication no
Use /etc/init.d/ssh reload to reload the changed configuration. Also try out that its disabled using putty and supply user name without RSA key file
Step 9: Optionally change the port number for extra security
open /etc/ssh/sshd_config file and change configuration for port.