Skip to content

Generate SSH key

Ed25519 is defined in RFC 8032 (Elliptic-curve signature scheme EdDSA); it is the default choice for new SSH keys because keys stay small while security and performance remain strong. Use RSA only when you must support legacy systems that do not accept Ed25519.

Interactive generation (lets you set a passphrase at the prompt—recommended):

Terminal window
ssh-keygen -t ed25519 -C "your@email.com" -f ~/.ssh/id_ed25519

Non-interactive with an empty passphrase (scripts or disposable environments only):

Terminal window
ssh-keygen -t ed25519 -C "$(whoami)@$(hostname -f 2>/dev/null || hostname)" -f ~/.ssh/id_ed25519 -N ""

Comment (-C) is a public label (often your email); it does not change cryptography.

Start an agent in the current shell:

Terminal window
eval "$(ssh-agent -s)"

Add to ~/.ssh/config:

Host *
AddKeysToAgent yes
UseKeychain yes
IdentityFile ~/.ssh/id_ed25519

UseKeychain and IdentityFile for extra keys (for example ~/.ssh/id_rsa) are macOS OpenSSH behaviors; load the key into the agent and store the passphrase in the Keychain:

Terminal window
ssh-add --apple-use-keychain ~/.ssh/id_ed25519

Omit UseKeychain (unsupported). Typical ~/.ssh/config snippet:

Host *
AddKeysToAgent yes
IdentityFile ~/.ssh/id_ed25519

Then:

Terminal window
ssh-add ~/.ssh/id_ed25519

macOS (copy ~/.ssh/id_ed25519.pub to the clipboard):

Terminal window
pbcopy < ~/.ssh/id_ed25519.pub

Linux (if xclip is installed):

Terminal window
xclip -selection clipboard < ~/.ssh/id_ed25519.pub

Otherwise print it and paste manually:

Terminal window
cat ~/.ssh/id_ed25519.pub

Appends your public key to ~/.ssh/authorized_keys on the server:

Terminal window
ssh-copy-id -i ~/.ssh/id_ed25519.pub user@remote.example

For GitHub (and similar), add the public key in the provider’s SSH key settings—not the private key.