Pages

Thursday, September 17, 2015

How to login to unix machines with out password using SSH ?





1. Windows to UNIX server

    1. Create your private key using Putty ken gen



Click on Generate, then drag the mouse the save the key as private key

    1. Save the file as test.ppk
    2. Log on to UNIX server
    3. Cd .ssh ( under home dir )
    4. Create new file authorized_keys or edit the file
    5. Then add your private key their …. ( it is single line )

Example : ssh-rsa AAAAB3NzaC1yc2EAAAABJQAAAIEAklJzYkmTbFKi6xE9o1kYqEU3YS+iOmY6aNOPm2QmljbigiziqI6w+zrckBXiWvABtRdp712mrkTUPA7Idmss+0lWGRtHdgxxfDQsvJj5bpm56K/4Cw83nSvj3TdtvwUiri7X4sje12Qlr71iECqDZFwKayGTcK0M0bLuZY4C+a8= rsa-key-20080102 - test


    1. Also add test at the end of the line
    2. Again open putty
    3. Enter Hostname
    4. Click on ssh then auth , give the location of ppk file




Now we can login without password!!!!!!!!!!!!!!


Few Troubleshooting

Server refused our key : Problem on Unix server , check the authorized_keys file

Correct login 


 

Then enter the password (Passphrase) for your private key




UNIX to UNIX (from server A to Server B)

On Server A
    1. Logon to .ssh folder on Server A
    2. Ran ssh-keygen -t rsa
    3. Give blank for all the details ( screen shot )

Generating public/private rsa key pair.
Enter file in which to save the key (/home/beausr/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /home/beausr/.ssh/id_rsa.
Your public key has been saved in /home/beausr/.ssh/id_rsa.pub.
The key fingerprint is:
98:97:fc:12:d3:2c:dc:7c:25:25:79:87:89:2f:f2:0d beausr@cic00152

    1. that will generate two files
-rw------- 1 beausr beausr 883 Jan 02 08:46 id_rsa
-rw-r--r-- 1 beausr beausr 225 Jan 02 08:46 id_rsa.pub
1.5 copy the id_rsa.pub to text file (it is single line )

    1. log on to server B
    2. log on to .ssh folder
    3. Create new file authorized_keys or edit the file
    4. Then add server A’s private key their …. ( it is single line )
Step 5 to 8 can be done in  single command 

ssh-copy-id -i ~/.ssh/id_rsa.pub <IP of server B>



Example : ssh-rsa AAAAB3NzaC1yc2EAAAABJQAAAIEAklJzYkmTbFKi6xE9o1kYqEU3YS+iOmY6aNOPm2QmljbigiziqI6w+zrckBXiWvABtRdp712mrkTUPA7Idmss+0lWGRtHdgxxfDQsvJj5bpm56K/4Cw83nSvj3TdtvwUiri7X4sje12Qlr71iECqDZFwKayGTcK0M0bLuZY4C+a8= rsa-key-20080102 - userid@serverA


1.9 Save authorized_keys and log out
1.10 Now you can login from Server A to B without password (Only A to B will work)

Few Troubleshooting

authorized_keys is important one and edit it carefully .. There may be other users using this
authorized_keys : remove unnecessary spaces on the file

1. Your home directory ~, your ~/.ssh directory  should be on permission ( chmod 700 )
 drwx------
2.Your ~/.ssh/authorized_keys should be ( chmod 600 )
3.SE linux can cause problem in some linux version , so you might need to disable it 

1 comment:

  1. On linux systems. ssh-copy-id can be used to copy
    the .pub fie directly to remote systems.

    ssh-copy-id -i ~/.ssh/id_rsa.pub remote-host

    http://www.thegeekstuff.com/2008/11/3-steps-to-perform-ssh-login-without-password-using-ssh-keygen-ssh-copy-id/

    ReplyDelete