Welcome To suyashjain.blogspot.com

For Latest and more contents visit http://www.i3w.in

Friday, July 24, 2009

SSH Access Without Password

Latest Versioon of this blog can be obtained from http://wiki.secureit.in/


There are certain situations where you do not want to use password while doing ssh to remote machine.(i.e) running some script which uses ssh to access remote machine.

This can be achieved by generating public/private key.

Example:

"Local Host" is the machine from where we want to access "Remote Machine" by using ssh.

Step1.

Run the following command on "Local Host"


ssh-keygen -t rsa 
        ssh-keygen -t rsa   
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa): <press enter>
Enter passphrase (empty for no passphrase): <press enter>
Enter same passphrase again: <press enter>
Your identification has been saved in /root/.ssh/id_rsa.
Your public key has been saved in /root/.ssh/id_rsa.pub.
The key fingerprint is:
03:78:2e:2c:1f:1a:41:f3:43:6d:7f:47:18:4b:c7:da root@localhost.localdomain


This command will generate public and private key files.

Private Key File : ~/.ssh/id_rsa

Public Key File: ~/.ssh/id_rsa.pub


Create ~/.ssh directory, id does not exist.


This is only what we have to do on "Local Host"


Now copy the content of Public key file(~/.ssh/id_rsa.pub) to Remoote host file ~/.ssh/authorized_keys


if the file and directory does not exist , create it.

That's all... now run the ssh command from local host to remote host.


Sample Public Key Content:

ssh-rsa AAAB3NzaC1yc2EAAAABIwAAAIEAxw2859hwrHT8t2m7LQQAsWNXEo8hBGtCdOcB8qofrMMoNcvyXScQjBMq3sSu8FIGozBeF1vMC4oCOlizx4qK F7oshMV/9SuMCSMwj5S5bFe8uYicuBplkKIU+2a4Ijk6d/w3ynyXtVLAfsoYUQ2TxG0DX8pt8DGGcckzCjqhTlc= root@localhost.localdomain