1

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:

  1. My /home/username directory has the ".ssh" folder with the files "known_hosts", "initialkey" and "initialkey.pub". I generated the initialkey files with RSA.

  2. 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".

  3. 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.

8
  • 1
    Check permitrootlogin in sshd_config
    – Jeff Schaller
    Commented Aug 6, 2016 at 1:30
  • 2
    What is the complete ssh command that you are using? if you are using a non-default key name (i.e. not id_rsa) then AFAIK you must pass it as an explicit -i option. What user are you trying to connect as - what was your purpose in copying keys to /root/.ssh and changing the AuthorizedKeysFile location in sshd_config? Commented Aug 6, 2016 at 1:44
  • 2
    The non-root user is probably unable to read root's authorized keys. Stop overriding the key file location.
    – Jeff Schaller
    Commented Aug 6, 2016 at 1:52
  • 1
    ... it would be ssh -i ~/.ssh/initialkey localhost... plus what @JeffSchaller said Commented Aug 6, 2016 at 1:52
  • 1
    Re: authorized keys in the user's .ssh dir: Yes
    – Jeff Schaller
    Commented Aug 6, 2016 at 1:56

1 Answer 1

2

SSH is very paranoid about keys. If any directory on the path is writable by anyone other than the owner it will not trust the key. Check the permissions on all the directories in the path. Permissions should be something like drwxr-xr-x or drwxr-x---. Permissions like drwxrwxr-x or drwxrwxrwx will cause the key to be untrusted.

1
  • They are all indeed write protected.
    – Sidd
    Commented Aug 6, 2016 at 1:44

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .