So I've been trying for the past two hours to SSH into my own computer via localhost. But it says "Permission Denied (public key)".
I am running Ubuntu 14 LTS on VirtualBox. Here're my current settings:
My /home/username directory has the ".ssh" folder with the files "known_hosts", "initialkey" and "initialkey.pub". I generated the initialkey files with RSA.
My "/etc/ssh" folder also has two RSA files - "ssh_host_rsa_key" and "ssh_host_rsa_key.pub" (these RSA keys are different from the ones in /home/username/.ssh folder). The "sshd_config" file has disabled password authentication, disabled root login and both public key and RSA authentication are enabled. The value of "AuthorizedKeysFile" is set to "/root/.ssh/authorized_keys".
In "/root/.ssh/authorized_keys", I've copied the above mentioned "initialkey.pub" file.
I've checked the permissions to make them all at least "r" for all users.
Still, the problem persists. Maybe my concept of how SSH into my local machine works is incorrect. As of now, I believe that "openssh server" is making my machine into a server, and by using ssh localhost command, I can log into that server even from the same machine.
UPDATE: The problem has been solved by changing the permission of the home directory. I used the command chmod 750 $HOME, which solved the issue. Thank you all for your inputs.