Nat Dempkowski
Nat Dempkowski

Reputation: 2440

Command line Git doesn't recognize keys generated using GitHub for Windows

I've setup GitHub for Windows and used it to create SSH keys which are associated with my account. I can perform git operations in the GitHub for Windows GUI, but when I try to run a command in Command Prompt like git clone [email protected]:whatever.git I get an error like the following:

C:\Users\Nat\Documents\GitHub>git clone [email protected]:natdempk/whatever.git
Cloning into 'whatever'...
Permission denied (publickey).
fatal: Could not read from remote repository.

Why is this happening when everything works from the GitHub for Windows GUI?

Upvotes: 1

Views: 381

Answers (1)

Nat Dempkowski
Nat Dempkowski

Reputation: 2440

When GitHub for Windows creates keys they are named github_rsa and github_rsa.pub. git expects keys to be named id_rsa and id_rsa.pub by default, so it will not find the keys from GitHub for Windows and will give you Permission denied (publickey). To fix this you should create an SSH config file for github.com as C:\users\<username>\.ssh\config that looks something like the following:

Host github.com
    HostName github.com
    PreferredAuthentications publickey
    IdentityFile ~/.ssh/github_rsa

This informs git to use the generated GitHub for Windows keys when performing operations that connect to github.com.

Upvotes: 2

Related Questions