This guide shows how to add an SSH key to your Debian/Ubuntu VPS.
Make sure to have your public key ready. On Windows, you can use eg. Puttygen to generate one https://www.puttygen.com/.
Login to your VPS using your username and password and change to the root user using "su -".
Create a .ssh directory:
mkdir .ssh
Create an ssh public key file:
nano authorized_keys
Paste your PUBLIC! key in here. Do not paste your private key on the server.
Open the SSH config file:
nano /etc/ssh/sshd_config
Disable password authentication by adding this line:
PasswordAuthentication no
In the sshd_config you can also change the SSH port, which we recommend.
To apply the changes make sure to reload the SSH Service with:
systemctl restart sshd.service
Before you close the active ssh connection make sure to open a new one and check if you can login!