Make sure your SSH key’s public key is present in the .ssh/authorized_keys file of the user you want to use them for:
/home/user/.ssh/authorized_keysfor a normal user/root/.ssh/authorized_keysfor root
Furthermore, make sure the directory and files have the correct permissions.
chmod 700 .ssh
chmod 600 .ssh/authorized_keysTest your access to the server using your SSH key (identity file) as a parameter to -i
ssh -i ~/.ssh/your_private_key username@hostDanger
Make 100% sure you have configured and tested your access to the server using SSH keys sufficiently before proceeding!
You can most definitely lose access to your server. Especially if you don’t have physical access to it. It might be recoverable with the help of your hosting provider, but it might also be unrecoverable.
Create a new file in the /etc/ssh/sshd_config.d/ directory, to disable any access through passwords.
PasswordAuthentication no
PermitRootLogin prohibit-passwordThen restart sshd
sudo systemctl restart sshdor even better, restart your system
sudo systemctl reboot