SSH Prompts for password even though private keys are available, presented to server and known to it

ssh

I've got an ubuntu desktop within a VirtualBox machine and I've got a strange behaviour with the openssh server :

  • when my user is not already connected to the server (first ssh connexion), it prompts for password even though privates keys are availiable (PuTTY + Pagent). After that first connection, if I open a secondary or a third connection it gets connected with the keys.
  • If I close all connections and open a new one it prompts for the password.
  • If I have let say 4 open connections and I close the first one (the one that prompted for the password), the fifth connection will be opened with the keys

Anybody already seen this ?

Thanks for the time spent helping

Best Answer

How is the user's home directory mounted? It sounds like, for whatever reason, the user's home directory is not available if the user is not logged in, so that sshd can't find the authorized_keys file.

Also, take a look at /var/log/auth.log on the server for any messages.

Update: if it's necessary to do password-less login, you can change the sshd_config file to look for authorzied_keys in a non-encrypted directory. http://www.openbsd.org/cgi-bin/man.cgi?query=sshd_config&sektion=5

I suppose something like this would work (not tested):

AuthorizedKeysFile /etc/ssh/pubkeys/%u/authorized_keys .ssh/authorized_keys

That should tell sshd to check for public keys in both the unencrypted location and the encrypted one. Check the man page for more info.