How to create an SSH key pair
To create an SSH key pair, run the ssh-keygen utility on your local machine. The ssh-keygen utility is available on all major operating systems. In macOS or Linux, run ssh-keygen in the Terminal app. On Windows, run ssh-keygen in the Command Prompt app.
Generating a key pair
Run the following command:
ssh-keygen -t ed25519 -C "your_email@example.com"For legacy systems that do not support Ed25519, use RSA:
ssh-keygen -t rsa -b 4096 -C "your_email@example.com"Key generation prompts
When prompted, choose a location to save the key (press Enter to accept the default):
Enter file in which to save the key (/home/user/.ssh/id_ed25519):Optionally enter a passphrase to protect the private key:
Enter passphrase (empty for no passphrase):
Enter same passphrase again:Result
Two files are created:
- Private key:
~/.ssh/id_ed25519— keep this file secret and never share it. - Public key:
~/.ssh/id_ed25519.pub— place this on servers you want to access.
Viewing the public key
cat ~/.ssh/id_ed25519.pubCopy the output — you will need it when adding the key to a remote server.