Step 1: Generating SSH Key
1.From the command line, enter ssh-keygen. (if you get an error in the command window, check if C:\Program Files\Git\usr\bin is part of your path) The command prompts you for a file to save the key in
Press enter to accept the default key and path, /c/Users//.ssh/id_rsa.
Enter and re-enter a passphrase when prompted.
The command creates your default identity with its public and private keys.
2.Configuring tortoise-git
Load the ssh key generated previously(id_rsa). it will prompt you to select the file. (default path of the ssh keys C:\Users\.ssh)
While loading it will ask for passphrase.. enter the passphrase that was given earlier. After this step putty will load the certificate.
Once the certificate is loaded, click on the 'Save private key' button. it will prompt for picking the folder in which the file to be saved. Better to keep it in the same one as ssh key folder (C:\Users\.ssh). specify the filename also.
Now you have to configure the TortoiseGit with the generated key file. right click on the repo folder select TortoiseGit>Settings
In the settings screen select Git > Remote
In remote screen, select origin.. it will populate the URL and other fields.
Click on the ellipses against the Putty Key field and select the private key file that was generated with puttygen.
The file format of the private key is
----BEGIN RSA PRIVATE KEY------
xxxxxxxyyxyyxyxyxy
----END RSA PRIVATE KEY-------
The error was
Couldn't load private key(unable to open file)
The file has read-write permission. Apart from this private key has a passphrase, I think it would be the reason for the error.
The public key configuration in my bitbucket account,
4 Answers
The thing is your PuTTy uses ssh v2 (and it's good) but you key is generated for version 3 probably.
After you click OK, generate a new key and try to upload it. Worked for me.
2If I understand you correctly, you didn't use puttygen to create a keypair, instead, you used ssh-keygen to generate a keypair with passphrase, then you loaded that private key into Putty and saved it as Putty.ppk and got the error Couldn't load Private Key (cannot open file).
What format was the private key (id_rsa) you created in?
If you open it in a text file is the first like similar to this:
-----BEGIN RSA PRIVATE KEY-----
or does it look like this:
ssh-rsa AWEdxRASFLMAF......
This appears to be, likely, an issue with you loading the public key instead of the private key to save as a .ppk. The screenshot you show has 2 files: id_rsa and id_rsa, but one of them is the private key file and the other is the public key. It's probable that you selected the public key if no file extensions were shown. Try re-importing the key by selecting the id_rsa file with the timestamp of 05-03-2018 12:36 in your screenshot above.
Verify the first line in that file is
-----BEGIN RSA PRIVATE KEY-----
before you do.
6I had this same message, and for me the problem was that I had two versions of putty. I am using git extensions, which can be installed to include putty (it is the 32 bit version of putty, and located in the git extensions program files directory). I also installed putty myself.
I had generated the key with the 64 bit putty installation, and was trying to use that key with the 32 bit version. I fixed the issue by changing my putty path in git extensions options.
picture of git extensions settings window to specify location of putty
1In one version of puttygen I had the exact same error message ("unexpected end of file"). In the latest (0.76), puttygen just hung indefinitely trying to import my key, and I had to kill the process.
Since I couldn't find any answers that helped me and I'm a C++ developer, I decided to debug puttygen since the source code is available (using 0.76).
The problem for me was that somehow at the end of my private key there was an extra space, and puttygen cannot handle that!
So, instead of the last line of my private key file ending with
"-----END RSA PRIVATE KEY-----"
it ended with
"-----END RSA PRIVATE KEY----- "
Puttygen is programmed to keep on scanning for more key information from the file until it finds a line that starts with "-----END " and ends with "PRIVATE KEY-----", and it doesn't handle EOF (end of file) properly at all!
I hope this helps somebody, this issue drove me nuts!
1