Linux – Can’t ssh into remote server unless I login locally on the server first

linuxsshUbuntu

I've set up ubuntu server on an old desktop and was able to log in with password no problem. I then set up ssh keys and disallowed logging in with passwords. I now have this weird issue where I get a public key denied error when trying to ssh remotely UNLESS I connect a monitor to the old desktop and log in to the server locally, then log in to the server remotely using the keys – this works.

I've checked the permissions for both the .ssh files/folders on both machines and they're fine: 755 for home directories, 700 for .ssh, 644 for id_rsa.pub, and 600 for id_rsa and authorized_keys.

Any idea what's going on here?

Best Answer

The answer was as Michal Politowski said in the comments. Encrypted home directory contained the .ssh folder, so it wasn't accessible to ssh command until I logged on locally and decrypted the folder. Solution was to create /home/ssh/%user%/ and place the authorized_keys file there, then direct ssh to look there via sshd_config. See comments for link to useful web page.

Related Question