Generate an SSH Key Pair
Generate the key pair
Run the following command to create a new SSH key pair using the Ed25519 algorithm:
ssh-keygen -t ed25519 -C "your_email@example.com"
Ed25519 is the recommended algorithm—it's faster, more secure, and produces shorter keys than RSA. The -C flag adds a comment (typically your email) to help identify the key later.
When prompted for a file location, press Enter to accept the default (~/.ssh/id_ed25519). You'll also be asked for a passphrase—adding one provides an extra layer of security in case your private key is ever compromised. You can leave it empty for convenience, but a passphrase is strongly recommended for production use.
Verify the key was created
Confirm that both files were generated:
ls -la ~/.ssh/id_ed25519*
You should see two files:
id_ed25519— Your private key. Never share this file with anyone. Its permissions should be600(owner read/write only).id_ed25519.pub— Your public key. This is safe to share and is what you'll copy to servers and services.
Copy the public key to your target
Display your public key:
cat ~/.ssh/id_ed25519.pub
For a remote server, the easiest method is ssh-copy-id, which appends your public key to the server's ~/.ssh/authorized_keys:
ssh-copy-id user@server
For GitHub, copy the output from cat above, then go to Settings → SSH and GPG Keys → New SSH Key and paste it in.
After adding the key, test the connection:
ssh -T git@github.com
You should see a message confirming your identity.