How to Create SSH Keys with OpenSSH on MacOS or Linux

Validated on 28 Aug 2019 • Last edited on 19 Jun 2025

DigitalOcean Droplets are Linux-based virtual machines (VMs) that run on top of virtualized hardware. Each Droplet you create is a new server you can use, either standalone or as part of a larger, cloud-based infrastructure.

Note
If you’re struggling with SSH and server management, try our managed products: Cloudways deploys pre-installed software stacks onto Droplets, and App Platform deploys and scales apps directly from your code repository, along with databases and serverless functions.

The standard OpenSSH suite of tools contains the ssh-keygen utility, which is used to generate key pairs. Run it on your local computer to generate a 2048-bit RSA key pair, which is fine for most uses.

ssh-keygen

The utility prompts you to select a location for the keys. By default, the keys are stored in the ~/.ssh directory with the filenames id_ed25519 for the private key and id_ed25519.pub for the public key. Using the default locations allows your SSH client to automatically find your SSH keys when authenticating, so we recommend accepting them by pressing ENTER.

Generating public/private ed25519 key pair.
Enter file in which to save the key (/home/username/.ssh/id_ed25519):
Warning

If you have previously generated a key pair, you may see a prompt that looks like this:

/home/username/.ssh/id_ed25519 already exists.
Overwrite (y/n)?

If you choose to overwrite the key on disk, you cannot authenticate using the previous key anymore. Selecting yes is an irreversible destructive process.

Once you select a location for the key, you are prompted to enter an optional passphrase which encrypts the private key file on disk.

If you enter one, you have to provide it every time you use this key (unless you are running SSH agent software that stores the decrypted key). We recommend using a passphrase, but you can press ENTER to bypass this prompt.

Created directory '/home/username/.ssh'.
Enter passphrase (empty for no passphrase):
Enter same passphrase again:

This is the last step in the creation process. You now have a public and private key that you can use to authenticate.

Your identification has been saved in /home/username/.ssh/id_ed25519.
Your public key has been saved in /home/username/.ssh/id_ed25519.pub.
The key fingerprint is:
SHA256:v/d5p9UJP2dx5G4dSUN92OXA5jgBpRxidE62EXAMPLE [email protected]

The key's randomart image is:
+--[ED25519 256]--+
|      E== *o...++|
|     o.+ O +. =o+|
|        . *  = o+|
|         . .o ooo|
|        S .  o +o|
|         .    o.B|
|          .    +O|
|           ..  ==|
|          .. .+o.|
+----[SHA256]-----+

From here, you can:

We can't find any results for your search.

Try using different keywords or simplifying your search terms.