We help IT Professionals succeed at work.

Putty Generated .pub keys

longshot_tw2
longshot_tw2 asked
on
A user has created a key pair with puttygen.   They have sent me the. pub key.   I would like to copy and paste it into their authorized_keys file.   But it is in the wrong format, is there a utility that will reformat the file?   Or can someone expain how to easily do this.  A windows utility would be best, but any suggestions would help.
Comment
Watch Question

Commented:
What format is it in? Different ciphers (SSH1, dsa, tsa etc) use different formats, but still should work
CERTIFIED EXPERT
Most Valuable Expert 2013
Top Expert 2013

Commented:
puutygen has an output format option (-"-O")

From the manpage:

-O output-type
Specify the type of output you want puttygen to produce. Acceptable options are:
private
Save the private key in a format usable by PuTTY. This will either be the standard SSH-1 key format, or PuTTY's own SSH-2 key format.
public
Save the public key only. For SSH-1 keys, the standard public key format will be used ('1024 37 5698745...'). For SSH-2 keys, the public key will be output in the format specified by RFC 4716, which is a multi-line text file beginning with the line '---- BEGIN SSH2 PUBLIC KEY ----'.
public-openssh
Save the public key only, in a format usable by OpenSSH. For SSH-1 keys, this output format behaves identically to public. For SSH-2 keys, the public key will be output in the OpenSSH format, which is a single line ('ssh-rsa AAAAB3NzaC1yc2...').
fingerprint
Print the fingerprint of the public key. All fingerprinting algorithms are believed compatible with OpenSSH.
private-openssh
Save an SSH-2 private key in OpenSSH's format. This option is not permitted for SSH-1 keys.
private-sshcom
Save an SSH-2 private key in ssh.com's format. This option is not permitted for SSH-1 keys.

wmp

Author

Commented:
The format is DSA or RSA we support both.   But the issue is, the puttygen seems to put comments, and puts the key on multiple lines.  So if I do a simple copy and paste I have to remove the comments, remove the end of line markers so it's on one line, there a set of = signs at the end of the keys not sure if they belongs.

What I want to do is take a .pub key that is correctly created by puttygen, and directly import it or cut and paste it into the authorized_keys file of a linux server.  Instead of me having to make a bunch of modifications to get the key in the proper format.
CERTIFIED EXPERT
Most Valuable Expert 2013
Top Expert 2013

Commented:
Did you read my suggestion?
CERTIFIED EXPERT
Most Valuable Expert 2013
Top Expert 2013

Commented:
-O public-openssh

Author

Commented:
sorry your comments posted after I was done typing.

So you run (assuming it is installed in c:\)  C:\ puttygen -0 public-openssh from a command prompt,correct?  It will then export in the proper format?

Is there something that can be done with a .pub file already in the wrong format?

Author

Commented:
Sorry forgot to mention in my original post that I working with windows puttygen.

Commented:
if you can show an example of the output, I'm sure someone can give you a bit of perl / awk / sed that will change it to the required format
CERTIFIED EXPERT
Most Valuable Expert 2013
Top Expert 2013

Commented:
1) Yes

2) Try

puttygen old_key_file.pub -O public-openssh

Author

Commented:
says can't open private key,  Then opens the windows app.   It appears the windows app is only capable of convert private keys to openssh format.
CERTIFIED EXPERT
Most Valuable Expert 2013
Top Expert 2013

Commented:
Not sure whether it will work for PuTTY keys, but on the target system (with openssh) you could try

ssh-keygen -i -f old_key_file.pubnew_key_file.pub

Explore More ContentExplore courses, solutions, and other research materials related to this topic.