Generate an SSH key on macOS

Updated on

At LRob, secure access to your services relies on SSH keys.
This guide walks you through generating an SSH key on your Mac, step by step.

1. Check for existing keys

Before creating a new key, make sure there isn’t already one on your computer.
Open the Terminal and run:

ls -al ~/.ssh

If you see files such as id_rsa.pub or id_ed25519.pub, you already have a key.

2. Generate a new SSH key

To create a new key, use the command:

ssh-keygen -t ed25519 -C "votre_email@example.com"
  • -t ed25519: recommended algorithm, fast and secure.
  • -C: a comment (often your e-mail address).

💡 If your system is old and does not support Ed25519, use this instead:

ssh-keygen -t rsa -b 4096 -C "votre_email@example.com"

3. Choose where to store it

The Terminal prompts you:

Enter file in which to save the key (/Users/votre_utilisateur/.ssh/id_ed25519):

Press Enter to keep the default location.

4. Set a passphrase

You will be asked to set a passphrase (a password tied to the key).
This step is optional, and it means you have to type your password again each time you connect over SSH.

5. (Optional) Add the key to the SSH agent

If you use your SSH key regularly and want to avoid retyping the passphrase at every connection, we recommend adding it to the macOS SSH agent.

First, start the agent:

eval "$(ssh-agent -s)"

Then add your key:

ssh-add ~/.ssh/id_ed25519

ℹ️ If you leave your key in its default location (~/.ssh/id_ed25519), SSH will pick it up automatically even without the agent.

6. Display the public key

Once the key is generated, you need to send the public part of this key to your system administrator, or register it yourself in the administration interface (e.g. Plesk, SSH Keys menu).

To display the public key in your Terminal:

cat ~/.ssh/id_ed25519.pub

The output looks like this:

ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIB2n... commentaire

➡️ Copy the entire line, without any change or line break.
This public key is what will be used to authorize your secure access.

⚠️ Never share the private file (id_ed25519 without the .pub extension).
Only the public key (.pub) should be shared.

7. Copy and authorize the key

Copy the public key you obtained in the previous step, then:

  • Give it to your administrator so they can add it to your account,
    or
  • Add it yourself through the SSH Keys menu in Plesk (extension available at LRob).

Once the key is authorized, you will be able to connect securely to our services without a password.

Example:

ssh username@srvXX.lrob.net