How to Configure SSH Authentication With No Password on VirtualBox VM


These are instructions for if you have multiple keys in your ~/.ssh folder. It also assumes you already have port forwarding for SSH already setup on your VM (you can already ssh in with a password).

On host machine:

ssh-keygen -t rsa -C "user@localhost"

You will see this:

Enter file in which to save the key (/Users/darryl/.ssh/id_rsa):

If ~/.ssh/id_rsa does not already exist you can press enter, if it does exist enter a different file path (ex. /Users/darryl/.ssh/my_vm_rsa).

Open up ~/.ssh/config and add/edit an entry to include the location of the key you created as the IdentityFile. It should look something like this:

Host localhost
  HostName localhost
  User user
  IdentityFile ~/.ssh/my_vm_rsa
  Port 2281 # host port for ssh configured in virtual box port forwarding settings

On guest machine:

Open up ~/.ssh/authorized_keys and insert the contents of the public key you generated above (the one with the .pub extension)

Restart ssh:

service sshd restart

Now you should be able to ssh into the guest machine without entering a password.

Notes 

See also