Password Less Ssh Remote Login with Public Key in Linux
Before I explain about ssh key login I will explain how to generate ssh keys using linux ssh-keygen command.The ssh-keygen command will generate two keys and will store in two different files.These two file are stored in the users home directory.You can provide your own names for the file or by default it will be stored in id_dsa(private key) and id_dsa.pub(public key) files.The passphrase is used to protect your key. You will be asked for it when you connect via SSH.If you want you can leave passphrase as blank.Below is the output for ssh-keygen command.
Step 1 ) Run ssh-keygen Command
[tom@Server1 root]$ ssh-keygen -t dsa
Generating public/private dsa key pair.
Enter file in which to save the key (/home/tom/.ssh/id_dsa):
Created directory ‘/home/tom/.ssh’.
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /home/tom/.ssh/id_dsa.
Your public key has been saved in /home/tom/.ssh/id_dsa.pub.
The key fingerprint is:
c5:5a:62:60:f2:a5:eb:22:7d:02:7a:be:f8:5c:aa:34 tom@Server1
The key’s randomart image is:
+–[ DSA 1024]—-+
| . o . |
| + + . |
| o o + |
| o = |
| . . S |
| . o . |
|.Eo = o |
|.=.+ + |
|oo*. |
+—————–+
[tom@Server1 root]$
Step 2 ) Change the permissions of the ~/.ssh/ directory
[tom@Server1 root]$ chmod 755 ~/.ssh
Step 3) For no password login, you can copy the content of id_dsa.pub to ~/.ssh/authorized_keys file of remote machine and need to set permission for that file as below
[tom@RemotServer1 root]$ chmod 644 ~/.ssh/authorized_keys
If you have public key , then you also use ssh direct login with ssh -x -i option. Try as below
[tom@RemotServer1 root]$ssh -x -i /etc/sysconfig/id_dsa.pub tom@Server1.expertslogin.com
Category: Linux Administration

