Passwordless SSH and SCP

On Mac

Remove or backup existing keys.

$ rm ~/.ssh/id_rsa
$ rm ~/.ssh/id_rsa.pub

$ chmod 700 ~/.ssh

Generate a ssh key pair. For more instruction following this link https://help.github.com/articles/generating-a-new-ssh-key-and-adding-it-to-the-ssh-agent/

$ ssh-keygen -t rsa -b 4096 -C "your_email@example.com"

Copy the id_rsa.pub to the server using scp command

$ scp ~/.ssh/id_rsa.pub <username>@<servername>:~/Downloads/

On Server

Create a directory

$ mkdir ~/.ssh

Copy pub key to authorized key list

$ cat ~/Downloads/id_rsa.pub >> ~/.ssh/authorized_keys

Change the permission to 600

$ chmod 600 ~/.ssh/authorized_keys

Now you should be able to ssh and scp without entering password. You can reuse the public key to more than one server to setup passwordless SSH. Sharing public key on multiple server does not increase security risk. Make sure that you DO NOT share the private key (id_rsa) to keep it safe.