3

I use ssh to remote into my Ubuntu desktop.

I have set it up to use key based authentication and disabled using the password to log in.

I have also configured iptables to only allow ssh from my internal network and the IP from my work and dropped everything else for added security.

Anyways, I am only able to gain access if I am already logged in. If I remote in and reboot for any reason, I get the permission denied pubkey message and it refuses to let me in.

For kicks, I used team viewer to log into my machine. After I logged myself in via team viewer, It let me ssh into it again.

Is there a setting I may have forgot to check when editing my sshd_config file?

My home directory is encrypted if that makes any difference. This is possibly the culprit.

I originally configured everything on 16.04 but recently upgraded to 17.04. I left all configurations the same during the upgrade.

pa4080
  • 29,831

1 Answers1

4

It's because ssh daemon can't access to your authorized_keys file.

Change USERNAME to your username.

sudo mkdir /etc/ssh/USERNAME

Copy your key

sudo cp /home/USERNAME/.ssh/authorized_keys /etc/ssh/USERNAME

Own it

sudo chown -Rf USERNAME.USERNAME /etc/ssh/USERNAME
sudo chmod 644 /etc/ssh/USERNAME/authorized_keys

Add the following in /etc/ssh/sshd_config

AuthorizedKeysFile    /etc/ssh/%u/authorized_keys

Source: Passwordless SSH in Encrypted Home Directory

pa4080
  • 29,831
Artyom
  • 1,723