First you need to create a public/private key pair (If you don’t already have one). So that you can place your public key to any server you like which will allow you to connect to that server via ssh.
Digital Ocean provides a step by step tutorial for generating ssh keys. You can follow the steps here
Once you set up your SSH key, you need to add the public key to your server so that when your private key matches to that public key, you can connect to that server.
Again if you are using Digital Ocean, you can take a look at the following guide for adding your public ssh. But the principle should be similar for other services as well.
The path to your private key is generally
~/.ssh/id_rsa and to your public key is
~/.ssh/id_rsa.pub (In Linux based OS)