0

I am having a weird issue with SSH keys on my Ubuntu 18.04 Server PC. The server is just a PC that is connected to my main router at home.

I recently disabled SSH password authentication on the server to improve security, and as such, I generated SSH keys for my client PCs and transferred them to the server using ssh-copy-id user@ip (before disabling password auth). This worked fine, up until I had to restart the server, after which I keep getting the Permission denied (publickey) error.

The weird part is that if I connect the server PC to the same network powerline adapter as my client PC, which is directly connected to the main router, it works fine, but as soon as I move it back to the main router, it throws the same error.

Anyone have any idea what may be causing this?

Edit:

So turns out the issue is not related to the powerline adapter. The server does not accept SSH unless I have logged in once on the server machine, after which it works fine. But I still can't figure out how to resolve this issue either :(

Ivs
  • 1
  • 1
  • 4
  • Does your edit mean the problem is solved? What do you mean by "The server does not accept SSH unless I have logged in once on the server machine, after which it works fine"? Do you have to login locally first? When you ssh to a server for the first time from a "new" computer, the ssh client asks for confirmation if the server (host)is trusted (known). If you say yes, the ssh client makes a note of it. Was this the problem? – user68186 Sep 05 '19 at 14:58
  • @user68186 yep, I did mean that I have to log in locally first. It turns out the issue is that my home folder on the server is encrypted, and my authorized_keys file is in ~/.ssh. I've fixed this temporarily by moving authorized_keys out of the home folder, but this does mean that I have to enter my credentials to access home on the server. – Ivs Sep 05 '19 at 15:03
  • Please write you answer to the question in the **Your Answer** section below. In your question you did not mention anything about encryption. You may want to add that information in the question, in case some has a better solution. Finally after the required wait time, accept your answer (if there are no better solution) as the correct one by placing the green check mark next to it. – user68186 Sep 05 '19 at 15:09
  • 3
    Possible duplicate of [Encrypted Home directory not auto mounting](https://askubuntu.com/questions/115497/encrypted-home-directory-not-auto-mounting) – user68186 Sep 05 '19 at 16:00

1 Answers1

0

The issue was I had encryption enabled on my home folder on the server, which meant it could not read the authorized_keys file before I logged in. Resolved by removing the encryption on the home folder.

Ivs
  • 1
  • 1
  • 4