WARNING: This can lock you out if anything goes wrong
Use ssh-keygen to create key pair
ssh-keygen -t ed25519 -C "name@example.com"
Using xclip to copy public key from local machine
xclip -selection clipboard < ~/.ssh/id_ed25519.pub
Create file authorized_keys
at root home dir /root
touch authorized_keys
Change permissions to 644
chmod 644 authorized_keys
Add ssh pubkey to authorized_keys
using nano
or vim
File sshd_config
is located in /etc/ssh
Set following options
PubkeyAuthentication yes
AuthorizedKeysFile .ssh/authorized_keys
PasswordAuthentication no
ChallengeResponseAuthentication no
UsePAM yes
Restard sshd
systemctl restart sshd