Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm trying to set up an SSH server. I put my public key in the authorized_keys file, made sure the permissions were correct, etc.

When I restart the server (really just Ubuntu 12.04 desktop) and I ssh to it without first logging in on the server, I am asked for a password. If, however, I log into the server, I can ssh without being asked for a password.

auth.log has these lines when I have not logged in on the actual server:

mordor sshd[1605]: debug1: trying public key file /home/buck/.ssh/authorized_keys
mordor sshd[1605]: debug1: Could not open authorized keys '/home/buck/.ssh/authorized_keys': No such file or directory
share|improve this question

migrated from Jun 6 '12 at 5:29

This question came from our site for professional and enthusiast programmers.

Could it be that /home or /home/buck is not mounted before the first user log in? Could you paste the output of df? – krlmlr Jun 6 '12 at 0:55
Are you using encrypted home directories? – sarnold Jun 6 '12 at 0:55
this belongs on ubuntu. – Daniel A. White Jun 6 '12 at 0:58
@sarnold yes, that was the issue – buck Jun 6 '12 at 1:25
@DanielA.White I'll keep that in mind for next time. I wasn't familiar with the different SE sites. – buck Jun 6 '12 at 1:26
up vote 6 down vote accepted

The problem usually arises if your home directory is encrypted. The usual solution is to put your keys in a directory other than your home directory, and point your sshd_config file to it.

For example:

  1. Move your authorized_keys file on the server from /home/buck/.ssh/authorized_keys to something like /etc/ssh/keys/buck/authorized_keys
  2. set the permissions on this folder and the keys file: sudo chown -R buck:buck /etc/ssh/keys/buck/ and chmod 700 /etc/ssh/keys/buck/ and chmod 600 /etc/ssh/keys/buck/
  3. Edit /etc/ssh/sshd_config and change the line AuthorizedKeysFile %h/.ssh/authorized_keys to AuthorizedKeysFile /etc/ssh/keys/%u/authorized_keys
  4. sudo service ssh restart and you should be able to login without having to login to the server first.
share|improve this answer
awesome, thank you! The only error I ran into was that it should be %u instead of %h in the sshd_config line (to substitute username instead of home directory). – buck Jun 6 '12 at 1:28

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.