Thursday, October 18, 2007

Unix Login Without Password (Setting login keys)

Client : Machine from where you want to log-on
Server : Destination machine where you want to log-on from

1. On the client machine

Create the key(id_rsa) file with appropriate permissions

ssinghal@client$cd ~ssinghal/.ssh
ssinghal@client$touch id_rsa
ssinghal@client$chmod 600 id_rsa

Generate is_rsa file

ssinghal@client$ssh-keygen -t rsa

Press enter when you are prompted for a passphrase or for entering a file name ( accept the default)

Id is stored in ~ssinghal/.ssh/id_rsa

Your identification has been saved in /home/ssinghal/.ssh/id_rsa.
Your public key has been saved in /home/ssinghal/.ssh/id_rsa.pub.
The key fingerprint is:
2c:ce:0d:e4:53:83:d3:41:95:82:5f:cc:e5:8f:a1:6b ssinghal@MACHINENAME


2. copy the id_rsa.pub to server

Using any scp or ftp mechanism

3. On the server machine

SSH to the server machine and create keys file with appropriate permissions

ssinghal@server$cd ~ssinghal/.ssh/
ssinghal@server$touch authorized_keys2
ssinghal@server$chmod 600 authorized_keys2
ssinghal@server$cat id_rsa.pub >> authorized_keys2
( id_rsa.pub is client's public key)


Note: The username on client and server needs to be same ( If I am not mistaken)

Logout and from the client machine try to ssh again, you should be able to log-on with just your username

ssinghal@client$ ssh ssinghal@server

2 comments:

Anonymous said...

Thanks for the clear description of the procedure. Note that the username does not need to be the same on the client and server.

sandeep said...

@Tuan,
>> Note that the username does not need to be the same on the client and server.

I thought so , but when I tried it did not seem to work... maybe I missed out on some file permission settings .. thanks for the correction