Skip to main content

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):

  1. 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.
  2. Open Command Prompt or PowerShell

    • Press Windows + R, type cmd or powershell, and press Enter.
  3. Generate SSH Key

    • Type the command:
      ssh-keygen
      
    • Press Enter to accept the default save location (C:\Users\<username>\.ssh\id_rsa).
  4. Set a Passphrase (Optional)

    • When prompted, enter a passphrase for extra security, or just press Enter twice to skip.
  5. Complete

    • The keys are generated, usually two files: id_rsa (private key) and id_rsa.pub (public key) under .ssh folder in your user directory.

For Mac (macOS):

  1. Open Terminal

    • Find Terminal via Spotlight Search or in Applications > Utilities.
  2. 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"
      
  3. Save Key Location

    • Press Enter to accept the default file location (/Users/you/.ssh/id_ed25519 or /Users/you/.ssh/id_rsa).
  4. Set a Passphrase (Optional)

    • Enter a secure passphrase or press Enter to leave it blank.
  5. 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
      

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.