Generate SSH Key
Here are step-by-step instructions to generate an SSH key on both Windows and Mac systems:
For Windows (Windows 10/11):
-
Ensure OpenSSH Client is Installed
- Open Settings > Apps > Apps & Features > Optional Features.
- Check if OpenSSH Client is listed.
- If not, click Add a feature, find OpenSSH Client, and install it.
- Restart your computer if needed.
-
Open Command Prompt or PowerShell
- Press
Windows + R, typecmdorpowershell, and press Enter.
- Press
-
Generate SSH Key
- Type the command:
ssh-keygen - Press Enter to accept the default save location (
C:\Users\<username>\.ssh\id_rsa).
- Type the command:
-
Set a Passphrase (Optional)
- When prompted, enter a passphrase for extra security, or just press Enter twice to skip.
-
Complete
- The keys are generated, usually two files:
id_rsa(private key) andid_rsa.pub(public key) under.sshfolder in your user directory.
- The keys are generated, usually two files:
For Mac (macOS):
-
Open Terminal
- Find Terminal via Spotlight Search or in Applications > Utilities.
-
Generate SSH Key
- Run the command, replacing your email with your own:
ssh-keygen -t ed25519 -C "your_email@example.com" - If your macOS or server doesn't support Ed25519, use:
ssh-keygen -t rsa -b 4096 -C "your_email@example.com"
- Run the command, replacing your email with your own:
-
Save Key Location
- Press Enter to accept the default file location (
/Users/you/.ssh/id_ed25519or/Users/you/.ssh/id_rsa).
- Press Enter to accept the default file location (
-
Set a Passphrase (Optional)
- Enter a secure passphrase or press Enter to leave it blank.
-
Add SSH Key to ssh-agent
- Start the ssh-agent:
eval "$(ssh-agent -s)" - Add your private key:
ssh-add -K ~/.ssh/id_ed25519 - If using RSA:
ssh-add -K ~/.ssh/id_rsa
- Start the ssh-agent:
In both OS, your generated SSH public key is the one you copy and add to services like GitHub, servers, etc. The private key should remain secure and never shared.