Connect DigitalOcean droplets with SSH

First, create a key pair. This will eventually create a private key and a public key under ~/.ssh directory on your machine.

$ ssh-keygen -t ed25519

It will ask the location to which it store the key files. You can specify your preferred location if needed.

Enter file in which to save the key (/home/sammy/.ssh/id_ed25519):

It will also ask a passphrase. This is optional. It is like a password that you need to use your key on your machine. I did not choose it for simplicity.

Enter passphrase (empty for no passphrase):

Copy the public key to the server's authorized_keys file. The public key is located in /home/your-username/.ssh/id_ed25519.pub. The private key is located in /home/your-username/.ssh/id_ed25519. Note that the name of key files can be different if you specify your own name.

$ ssh-copy-id -i ~/.ssh/your-key-name username@hostname

Congratulation! Now you can access to the server without a password.

Simply use this command to ssh to your server:

$ ssh -i ~/.ssh/your-key-name username@hostname