Appending another key generated in PuTTYgen to authorized_keys file

1.9k views Asked by At

I allowed Amazon to create a key pair for me. It works, I can ssh in.

I used PuTTYgen to create another key pair.

Followed directions from https://help.ubuntu.com/community/SSH/OpenSSH/Keys and http://www.cyberciti.biz/tips/linux-multiple-ssh-key-based-authentication.html

  • I executed command cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys
  • restarted the ssh service

Resulting authorized_keys looks like this :

ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCIm2L1LrZji0ZjS0BFpo+lPresjSzBru2kZYQFwT2fB/6vsC+n1hPmA5peRkubMk5ahGawvqODX4ERYYMkP/imKK95el3Gx9n1zUO58PR2EH7qeRHZYtw1OwivDndTgB3eykJGtwJ80iyKa/H0yI8QdKNeQk91fRe9SntCHO63xfqvZKUjNgDtXhGmRAumCcwdMHU4viWlgIGcj7mARz+JDTD/8s8JbiW7UyUqxKGDwv0TZxxNbvIbUduQ61hkogPPaK9ECRBX5cc0iS44FgG8SbIGUZLt7/eV5tc8pAjQc5pWyZBDewV4E2HbCtHM6MoWtbmMKQjIzSauUnkUCWG/ crave
---- BEGIN SSH2 PUBLIC KEY ----
Comment: "rsa-key-20141212"
AAAAB3NzaC1yc2EAAAABJQAAAQEA03FN7q5+yoRw3Fp9iJbd70Mc1Cbrc+z8SsFT
DaP27uoJy9eRjizikkIEhJNAU9Ql86S78oJzfiw+DrWVeoMHBMmY6yV/KFHBYlhl
waJp7dk9hwlQyCZRY4iiZT2o+TPcYj0FCk1V/Am8svtlgVNuRfo9G4zmBeRc+Njt
zfTZDmUpN1u70FVNOhGNHq2rSyG+Q8RJO1pX8jg82kXusHxZRMK6LlhBdaWEbr2w
Y8X89Eqg2UjNfkl4cOmx3rvVfK6xHbKoeGPEdDXDKghiflM1GCNwG4khIBDBLXZs
8bYzeTcIKGa3WAN7MoO1tvVKwpMVHR673Ypz3dLpD53WjxNmCw==
---- END SSH2 PUBLIC KEY ----

The first one still works with the private key generated by Amazon but the second public key doesn't recognize the private key PuTTYgen created.

I get

Server refused our key

1

There are 1 answers

1
Martin Prikryl On BEST ANSWER

When I follow the (correct) instructions you have pointed to yourself, my id_rsa.pub file follows expected format:

ssh-rsa <key> comment>

Had you appended a public key in the above format, it would work.

While I believe you actually have not followed the instructions, but saved the public key from PuTTYgen is its own multi-line format (as we can see in your resulting authorized_keys).

OpenSSH server does not understand that format.

Solutions:

  • Either really follow the instructions you have pointed to completely (particularly generate the key pair using ssh-keygen)

  • Or follow PuTTYgen instructions and copy-paste the public key in OpenSSH format from PuTTYgen box labeled Public key for pasting into OpenSSH authorized_keys file.