1. Generate public and private keys using ssh-key-gen
[root@localhost .ssh]# ssh-keygen
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
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:
The key’s randomart image is:
+–[ RSA 2048]—-+
| + ..|
| + + oo|
| . = .+|
| + . o E ..|
| S o o o o|
| * o . o |
| . = |
| . . |
2. Copy the generated local machine’s public key to remote-host using ssh-copy-id
ssh-copy-id command will append the keys to the remote-host’s .ssh/authorized_key.
[root@localhost .ssh]# ssh-copy-id -i ~/.ssh/id_rsa.pub 10.21.170.1
/usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
/usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed — if you are prompted now it is to install the new keys
Number of key(s) added: 1
Now try logging into the machine, with: “ssh ‘10.21.170.1’”
and check to make sure that only the key(s) you wanted were added.
3. Login to remote machine using ssh without issuing password
[root@localhost .ssh]# ssh 10.21.170.1
Last login: Tue Oct 11 15:55:44 2016 from root