Graphite Reviewer is now Diamond

Setting up SSH keys with Git Bash for secure development

Greg Foster
Greg Foster
Graphite software engineer
Try Graphite


Note

This guide explains this concept in vanilla Git. For Graphite documentation, see our CLI docs.


Git Bash is a command-line interface for Windows that combines Git with Bash, a Unix shell. It allows Windows users to execute Git commands and Unix-like shell commands in a familiar environment. This tool is particularly useful for developers who prefer a Unix-style command-line experience on Windows systems.

Before you begin, ensure you have the following:

  • Git Bash installed on your Windows system.
  • A GitHub account.
  • Optional: Graphite CLI installed for enhanced Git workflows.
  1. Open Git Bash.

  2. Enter the following command, replacing your email address:

    Terminal
    ssh-keygen -t ed25519 -C "your_email@example.com"

    If your system doesn't support Ed25519, use RSA:

    Terminal
    ssh-keygen -t rsa -b 4096 -C "your_email@example.com"
  3. When prompted to "Enter a file in which to save the key," press Enter to accept the default location (/c/Users/your_user/.ssh/id_ed25519).

  4. At the prompt to enter a passphrase, you can choose to enter one for added security or leave it empty for convenience.

  1. Start the SSH agent in the background:

    Terminal
    eval "$(ssh-agent -s)"
  2. Add your SSH private key to the agent:

    Terminal
    ssh-add ~/.ssh/id_ed25519
  1. Copy the SSH public key to your clipboard:

    Terminal
    clip < ~/.ssh/id_ed25519.pub
  2. Log in to your GitHub account.

  3. Navigate to "Settings" > "SSH and GPG keys".

  4. Click "New SSH key", provide a descriptive title, paste your key into the "Key" field, and click "Add SSH key".

To verify that your SSH key is correctly configured:

Terminal
ssh -T [email protected]

You should see a message like:

Terminal
Hi username! You've successfully authenticated, but GitHub does not provide shell access.

Ensure that your Git operations use SSH instead of HTTPS:

  1. Check your current remote URL:

    Terminal
    git remote -v
  2. If the URL starts with https://, change it to SSH:

    Terminal
    git remote set-url origin git@github.com:username/repository.git

    Replace username and repository with your GitHub username and repository name, respectively.

If you're using Graphite to manage your Git workflows, ensure it utilizes your SSH configuration:

  1. Open Git Bash and run:

    Terminal
    gt config
  2. In the interactive menu, configure the following:

    • Git remote name: Ensure it matches your SSH-configured remote (usually origin).
    • GitHub repository information: Verify that Graphite correctly infers your repository name and owner from the SSH URL.

For more detailed configuration options, refer to Graphite's CLI documentation.

  • Permission denied (publickey): Ensure your SSH key is added to the SSH agent and associated with your GitHub account.
  • Host key verification failed: You might need to add GitHub to your known hosts by attempting to SSH into GitHub and accepting the prompt.
  • Multiple SSH keys: If you use multiple SSH keys, create a ~/.ssh/config file to specify which key to use for each host.

By following these steps, you've set up SSH keys with Git Bash, enhancing the security and convenience of your Git operations. Integrating these keys with Graphite further streamlines your development workflow.

Built for the world's fastest engineering teams, now available for everyone