Issue
I'm having something very similar to: SSHD Gives error could not open Authorized Keys, although permissions seem correct but not exactly the same thing.
When I try to connect to server with my user account I see the following error message in /var/log/secure
The error message says:
Could not open authorized keys '/home/<username>/$HOME/.ssh/authorized_keys': No such file or directory
which makes perfect sense, but when I go to the /etc/ssh/sshd_config
folder to see where the sshd
service should look for my authorized key folder it shows $HOME/.ssh/authorized_keys
so i'm not sure why SSH is trying to append my /home/<username>
to $HOME/.ssh/authorized_keys
. I did double check and ran the following cmd: echo $HOME
just to make sure $HOME
wasn't set improperly. If anyone has any ideas it would be much appreciated.
Solution
sshd_config
is not a shell script. $HOME/.ssh/authorized_keys
is taken as a literal path, and since it does not start with /
, it is appended to the user's home directory.
You should replace $HOME
with the token that sshd
interprets as the user's home directory, or simply use the relative path .ssh/authorized_keys
(which, by the way, is the default).
AuthorizedKeysFile %h/.ssh/authorized_keys
Answered By - chepner Answer Checked By - Marilyn (WPSolving Volunteer)