SSH issue using key - root works, second user don't

I have issue that root connection with my set of SSH keys is working without issues, but I have created second user, and using the same key I can not connect - Permission denied (publickey)., I am not so advanced with SSH, possibly I need to add that created user to SSH somehow, I am using OpenSSH. Any ideas why it can be like that?

Did you add the publickey to the authorized_keys file of that new user?

2 Likes

Solved it, just in case anyone would have this issue - the rootcause is of course, @Jappe said is availability of authorized_keys and the second is ownership and rights. The solution is:

  1. Login as root, create .ssh folder in new-user-name folder and copy or create authorized_keys file
mkdir ~/.ssh 
cp ~/.ssh/authorized_keys /home/new-user-name

or
echo "ssh-ed25519 AAAA-KEY-HERE-AAAA.... new-user-name" | sudo tee -a /home/username/.ssh/authorized_keys > /dev/null

  1. login as that new-user-name and apply nesseccary ownership, permissions and rights
su new-user-name
sudo chmod 700 ~/.ssh
sudo chmod 600 ~/.ssh/authorized_keys
sudo chown -R new-user-name:new-user-name ~/.ssh
  1. resttart SSH
    sudo systemctl restart ssh
1 Like