Configuring Git for Windows to Locate Your Private RSA Key for SSH Authentication


3 views

When transitioning from Linux to Windows with Git for Windows, many developers encounter authentication issues because the SSH client doesn't automatically discover private keys in the same way as Linux systems. While password authentication might work as a temporary solution, proper RSA key configuration is essential for secure and convenient Git operations.

1. Standard Key Placement: The simplest approach is placing your private key in the default location that ssh.exe expects:

C:\Users\YourUsername\.ssh\id_rsa (private key)
C:\Users\YourUsername\.ssh\id_rsa.pub (public key)

2. Custom Key Location: If you need to store keys elsewhere, create or modify the SSH config file:

Host github.com
    HostName github.com
    User git
    IdentityFile C:\path\to\your\private\key
    IdentitiesOnly yes

Save this as config (no extension) in your .ssh directory.

For TortoiseGit users, additional steps ensure proper key integration:

  1. Right-click in any folder → TortoiseGit → Settings
  2. Navigate to "Network"
  3. Under "SSH client", point to C:\Program Files\Git\usr\bin\ssh.exe
  4. Ensure "Autoload Putty Key" is unchecked if using OpenSSH keys

For system-wide configuration, set the GIT_SSH_COMMAND environment variable:

setx GIT_SSH_COMMAND "ssh -i C:\path\to\private\key"

Or for PowerShell:

[Environment]::SetEnvironmentVariable("GIT_SSH_COMMAND", "ssh -i C:\path\to\private\key", "User")

Test your setup with:

ssh -T git@github.com

You should see a successful authentication message if configured properly.

Windows often requires adjusting key file permissions:

icacls C:\path\to\private\key /inheritance:r
icacls C:\path\to\private\key /grant:r "%USERNAME%":"(R)"

This prevents "Permissions are too open" errors from SSH.

For better key management, consider using ssh-agent:

# Start the agent
eval $(ssh-agent -s)

# Add your key
ssh-add C:\path\to\private\key

Add these commands to your shell startup file for persistence.


When transitioning from Linux to Windows with Git, one common pain point is SSH key management. While Linux typically stores keys in ~/.ssh/, Windows environments require explicit configuration to locate your private RSA key.

Create or modify the SSH config file at C:\Users\[YourUsername]\.ssh\config:

Host github.com
    HostName github.com
    User git
    IdentityFile C:/path/to/your/private_key
    IdentitiesOnly yes

Alternatively, set the GIT_SSH_COMMAND environment variable:

set GIT_SSH_COMMAND="ssh -i C:/path/to/your/private_key"

For permanent setup, add this to your system environment variables or Git Bash profile.

In TortoiseGit settings:

  1. Go to Network → SSH client
  2. Set path to ssh.exe (typically in Git installation directory)
  3. Add -i C:/path/to/your/private_key to the "Extra parameters" field

Verify your configuration works with:

ssh -T git@github.com -i C:/path/to/your/private_key
  • Permission issues: Ensure your private key has restricted permissions (chmod 600 equivalent in Windows)
  • Path formatting: Use forward slashes or double backslashes in Windows paths
  • Key format: Convert keys from PuTTY format if needed: puttygen key.ppk -O private-openssh -o key.pem

For project-specific keys, set core.sshCommand:

git config core.sshCommand "ssh -i C:/path/to/your/private_key"