Passwordless ssh or scp using ssh-keygen & ssh-copy-id

Machine-1 to Machine-2

 

[oracle@machine-1 ~]$ ssh-keygen
Generating public/private rsa key pair.
Enter file in which to save the key (/home/oracle/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /home/oracle/.ssh/id_rsa.
Your public key has been saved in /home/oracle/.ssh/id_rsa.pub.
The key fingerprint is:
19:84:d4:f0:c9:19:c1:83:82:f2:8c:40:72:6f:09:76 oracle@machine-1.eudra.org
The key's randomart image is:
+--[ RSA 2048]----+
|o.+.E.o*+.       |
|+o.+..o+++       |
|.=  +.  *.       |
|. o.     o       |
|        S        |
|                 |
|                 |
|                 |
|                 |
+-----------------+
[oracle@machine-1 ~]$ ssh-copy-id -i ~/.ssh/id_rsa.pub machine-2
oracle@machine-2's password:
Now try logging into the machine, with "ssh 'machine-2'", and check in:

  .ssh/authorized_keys

to make sure we haven't added extra keys that you weren't expecting.

[oracle@machine-1 ~]$ ssh machine-2
Last login: Wed Dec  7 07:32:47 2016 from 10.40.1.12
[oracle@machine-2 ~]$ exit
logout
Connection to machine-2 closed.
[oracle@machine-1 ~]$

Machine-2 to Machine-1

Repeat above steps from Machine-2

 

***** Offcourse this will only work if there is no firewall blocking connection on port 22 between Machine-1 & Machine-2