Cannot upload public SSH key generated by puttygen on Windows

Asked by JianminX

Platform: Windows XP SP2
puttygen version: 0.54
pageant version: 0.54

I tried several times with different key type but alway failed to import. my last public key follows.
Comment: ""

Please advise.

Question information

English Edit question
Launchpad itself Edit question
No assignee Edit question
Last query:
Last reply:
Revision history for this message
JianminX (heidan) said :

Every time I tried to import, I got 'Invalid public key'.

Revision history for this message
Kemel Zaidan aka Legendario (kemelzaidan) said :

Open the key with a text editor an copy all the content. Try to paste it on the launchpad import page, instead of pointing to the file on your computer.

Revision history for this message
Diogo Matsubara (matsubara) said :

Hello Jianmin,

instead of using the contents of the saved key, use the contents of "Public key for pasting into OpenSSH authorized_keys file:" of the Putty Key Generator application.
It should look like:

ssh-rsa AAAAB3NzaC1yc2EAAAABJQAAAIEAvqA2RtZyOq17uj/xUcQJS81BFugXYCsVx/Jk3Zl45f59sJsbB8JFzZ7xCFsCZmv4fg8YWCGEIXun1KTNyE45NZwtUysFa1QyySrm

Revision history for this message
Diogo Matsubara (matsubara) said :

No new line character:

ssh-rsa AAAAB3NzaC1yc2EAAAABJQAAAIEAvqA2RtZyOq17uj/xUcQJS81BFugXYCsVx/Jk3Zl45f59sJsbB8JFzZ7xCFsCZmv4fg8YWCGEIXun1KTNyE45NZwtUysFa1QyySrmUWis7P5Qei7GkAknKi+MA4cafRFMJ1WA1jo54Pzjrde5HHnxr27ErFInDv7idGItHN0XwN0=

Revision history for this message
Dave Anderson (davious) said :

I had the same woes you did.
Puttygen displays a text box with the cut and paste version of the key.
First I saved the public key, then opened it up and tried cutting and pasting without luck.
Then I noticed Puttygen's textbox and bingo.

Revision history for this message
kayatsu (kayatsu) said :

what you need to do, copy paste from the text box that puttygen provide not viewing file from the generated public key files.

Revision history for this message
lborgman (lennart-borgman) said :

I have added a note about this on [[CreatingAnSSHKeyPair]]

Could someone perhaps correct the link there to this page. I have no idea how to make it prettier.

But it would of course be much better if Launchpad understood the format stored in the file too.

Revision history for this message
Murad Biskin (muradbiskin) said :

I had this problem also and i copy paste all the text from where it say's
Public key for pasting into OpenSSH authorized_keys file

Revision history for this message
Rudy Lattae (rudylattae) said :

Here's my 5 pesos worth... (psst! you may realize that this is pretty much what folks like Diogo have been saying up there :)

Easy way out (this was mentioned earlier):
- Go through the process of generating a key with Puttygen.
- Save your keys (public and private) But don't close the Puttygen window just yet!
- Copy the public key from the Puttygen window. This way you get key, the whole key and nothing but the key.

OR (if you went ahead and generated the files then closed Puttygen -- like I did):

Here is an example of a generated public key (note -- it's not real):

Comment: "rsa-key-20080829"

Basically the actual key is the gibberish after the "Comment" line and before the "---- END..." line.
So you would have to copy your key from "alp1hanuQSmericgib21..." all the way to "==".
Then you should prefix the whole thing with "ssh-rsa " -- note the space after the "a".
And finally you should tack on the entry in comment (in this case "rsa-key-20080829") without the quotes ("") at the end of the key. Again separate it from the main key with a space.

You must make sure the whole thing is on one line. So in this case you would have:

ssh-rsa alp1hanuQSmericgib21berisDShalphanume1ricgibberish2salpdffZXhanumericgibberishericgib21berisDShalphanume1ricgibberish2salpdffZXhanumericgibberishalp1hanuQSmeric25SF6gib21berisDShalpAHJ34Khanume1ricgbKY2PQ== rsa-key-20080829

It probably looks like it's on more than one line (the text is being wrapped) but it's definitely all on one line.

So taking this back to Jianmin's original question, you would end up with (again ignore any virtual wrapping -- the whole thing is on one line):

ssh-rsa AAAAB3NzaC1yc2EAAAABJQAAAIEAvqA2RtZyOq17uj/xUcQJS81BFugXYCsVx/Jk3Zl45f59sJsbB8JFzZ7xCFsCZmv4fg8YWCGEIXun1KTNyE45NZwtUysFa1QyySrmUWis7P5Qei7GkAknKi+MA4cafRFMJ1WA1jo54Pzjrde5HHnxr27ErFInDv7idGItHN0XwN0=

Hope this helps someone.


Revision history for this message
Rodin Shih (schludern) said :

Yeah, I use puttygen load my private key again and saw the write form of a DSA ssh2 key, after copy to lp and submit, import successful finally...

The prefix of a DSA key is "ssh-dss" not "ssh-dsa" :'( , the other parts is same with rsa example of Rudy Lattae's.

Hope this will be useful for some guys used ssh2 dsa like me ...

Revision history for this message
Giorgio Wicklein (giowck) said :

Thanks Rudy Lattae! It works!!

Revision history for this message
Fabio Neukirchen (fneukirchen) said :

Thanks Ruddy! Works fine to me!

Revision history for this message
Pablo Olmos de Aguilera Corradini (pablox) said :

Thanks Rudy, it helped me! For some reason after creating the public key (in Xubuntu Jaunty) after the "==" said: user@hostname and it told me "Invalid Public Key". It looks like the system don't accept characters such "@" for the comment, I changed it and then it worked :).

Revision history for this message
Anthony Dillon (ya-bo-ng) said :

Thanks Rudy, worked great for me! Seem's to me the help page should be updated to tell Windows users to prefix the key from PuTTY Key Gen with "ssh-rsa " as you said. Also end it with the nickname of the machine.

Thanks again!

Can you help with this problem?

Provide an answer of your own, or ask JianminX for more information if necessary.

To post a message you must log in.