SSH Login Without Password Using ssh-keygen & ssh-copy-id

Passwordless login ,yeah as name suggested its very much tempting and will give you a comfort zone.
ssky-keygen and ssh-copy-id these two commands will make your life easy in that case, lets follow them as below :-

ssh-keygen creates the public and private keys. ssh-copy-id copies the local-host’s public key to the remote-host’s authorized_keys file. ssh-copy-id also assigns proper permission to the remote-host’s home, ~/.ssh, and ~/.ssh/authorized_keys.

Step 1: Make public and private keys using ssh-key-gen on local-host

AJM@local-server$ [Note: You are on local-host here]

AJM@local-server$ ssh-keygen
Generating public/private rsa key pair.
Enter file in which to save the key (/home/AJM/.ssh/id_rsa):[Enter key]
Enter passphrase (empty for no passphrase): [Press enter key]
Enter same passphrase again: [Pess enter key]
Your identification has been saved in /home/AJM/.ssh/id_rsa.
Your public key has been saved in /home/AJM/.ssh/id_rsa.pub.
The key fingerprint is:
22:a3:2e:sf:45:55:18:01:13:e5:qe:89:22:q2:l5:89 AJM@local-server

Step 2: Copy the public key to remote-host using ssh-copy-id

AJM@local-server$ ssh-copy-id -i /home/AJM/.ssh/id_rsa.pub remote-server
AJM@remote-server's password:

Now do ssh to remote-server and check:

/home/AJM/.ssh/authorized_keys  <<-- you will find your public key appended in here.

Note: ssh-copy-id appends the keys to the remote-host’s .ssh/authorized_key.

Step 3: Login to remote-host  password

AJM@local-server$ ssh remote-server <<-SSH will not ask for passwd here
Last login: Thu Dec 9 22:19:33 2014 from 10.0.0.6

AJM@remote-server

Comments

Popular posts from this blog

HP-UX virtual Machine Cheat Sheet

How to run fdisk in non-interactive mode