Linux: Creating a ssh keypair with puttygen

Hi,

use the following steps to create a ssh key pair with puttygen and import the public key on a linux hosts.

Start puttygen and generate an 4096 Bit RSA Key.

Generate an 4096Bit RSA Key
Generate an 4096Bit RSA Key

Set a strong password and save it (D:\temp\private.ppk in this example) at a secure location.

Secure and save your private key
Secure and save your private key

Export your private key as OpenSSH compatible key (for example D:\temp\private.key) and copy the key to your linux box.

Export your key in openssh format
Export your key in openssh format

Copy the key to the your home directory

d:\> pscp d:\temp\private.key michael@devdeb:.ssh/id_rsa

Export your public key to ~/.ssh/id_rsa.pub


michael@devdebt > chmod 600 ~/id_rsa
michael@devdebt >  ssh-keygen -e -f ~/id_rsa > ~/.ssh/id_rsa.pub


michael@debdevt:~/.ssh $ cat id_rsa.pub
---- BEGIN SSH2 PUBLIC KEY ----
Comment: "4096-bit RSA, converted by michael@debdevt from OpenSSH"
AAAAB3NzaC1yc2EAAAABJQAAAgEAmlBW8LR5J4E8NbiyrYZQxN9RsFjfP9pwPJbOcUVlop
v+u5TIZm8S6AW3sVFTElYgeQoi5f3csvfQBIAWCu+yTB8/q7b1gqk9TIGfxQS1mJHhit+v
3cGb/QKazqN0wz357keEZxP5kl4q4YBSEtUIVfvlLghuLNu53CjpexrSX31q9KwzSY7vUO
RpOYwbWNJb/hAudXfUk2nDMdPtVzte8hPpq73apFT1nORFSAI1TZlj3rVubX0434iGrK7O
6gbjGJjukxeqDVWjYSFpk2MROwUnnJWgS0ueRBu2gsaDIEw6qx9vIEKcj0O30uZvyPc9/I
i1K9PKAnmzv+zUTLqLw9+vxNM3hueGXbk25Qv4aFuxzz8vpIh5qP5ZVswMm5+nis6paYXH
wStZc1yUVeL5XYVjZoBZ4+3jsQUOcBEWFACsxWP6HaLbuxl+DaGO/f6sPYC0QuOydFgV9W
JcjXzmodnAoh5mBHZKTLDJEIOmrHVX2PT5iQoDljRPO1xtP4j5AkcAaNfyT51FNgdeRyRj
zklK6Lqkem3V/CakfBzzySgDs3VUrkZnFDXkGjKqnR9v91PzzpcZQ13VS4kZvc04vbsAJN
h5c/X+aTHcwJv2vlV82nNumur686gZW0BriKtvkJiurHKmlxtPLwlbZ3vl0IVM6nhloBDS
huun/WUa/oM=
---- END SSH2 PUBLIC KEY ----

Add the public key to file ~/.ssh/authorized_keys. You have to convert id_rsa.pub (SSH2 PUBLIC KEY format) to the format authorized_keys expects and set the correct file permissions. Convert it “manually”:


michael@debdevt:~/.ssh # echo -n  "ssh-rsa " >> ~/.ssh/authorized_keys
michael@debdevt:~/.ssh # cat ~/.ssh/id_rsa.pub | tail -n+3  | head -n-1 |tr -d '\n' >> ~/.ssh/authorized_keys
michael@debdevt:~/.ssh # echo " ${USER}@${HOSTNAME}" >> ~/.ssh/authorized_keys

or use ssh-keygen


michael@debdevt:~/.ssh #  ssh-keygen -i -f id_rsa.pub >> authorized_keys

 

Set permissions


michael@debdevt:~/.ssh # chmod 600 ~/.ssh/authorized_keys

A line like this was added
michael@debdevt:~$ cat .ssh/authorized_keys
ssh-rsa AAAAB3NzaC1yc2EAAAABJQAAAgEAmlBW8LR5J4E8NbiyrYZQxN9RsFjfP9pwPJbOcUV
lopv+u5TIZm8S6AW3sVFTElYgeQoi5f3csvfQBIAWCu+yTB8/q7b1gqk9TIGfxQS1mJHhit+v3c
Gb/QKazqN0wz357keEZxP5kl4q4YBSEtUIVfvlLghuLNu53CjpexrSX31q9KwzSY7vUORpOYwbW
NJb/hAudXfUk2nDMdPtVzte8hPpq73apFT1nORFSAI1TZlj3rVubX0434iGrK7O6gbjGJjukxeq
DVWjYSFpk2MROwUnnJWgS0ueRBu2gsaDIEw6qx9vIEKcj0O30uZvyPc9/Ii1K9PKAnmzv+zUTLq
Lw9+vxNM3hueGXbk25Qv4aFuxzz8vpIh5qP5ZVswMm5+nis6paYXHwStZc1yUVeL5XYVjZoBZ4+
3jsQUOcBEWFACsxWP6HaLbuxl+DaGO/f6sPYC0QuOydFgV9WJcjXzmodnAoh5mBHZKTLDJEIOmr
HVX2PT5iQoDljRPO1xtP4j5AkcAaNfyT51FNgdeRyRjzklK6Lqkem3V/CakfBzzySgDs3VUrkZn
FDXkGjKqnR9v91PzzpcZQ13VS4kZvc04vbsAJNh5c/X+aTHcwJv2vlV82nNumur686gZW0BriKt
vkJiurHKmlxtPLwlbZ3vl0IVM6nhloBDShuun/WUa/oM= michael@debdevt

If you want to copy your public key to other boxes. Convert SSH2 PUBLIC KEY format and copy the file


michael@debdevt:~/.ssh # ssh-keygen -i -f id_rsa.pub > id_rsa
michael@debdevt:~/.ssh # ssh-copy-id -f -i ~/.ssh/id_rsa michael@debdev2

Configure your PuTTY Session to use the ssh key

Configure PuTTY to use the ssh key
Configure PuTTY to use the ssh key

And Login to your linux box

Login
Login

Have fun 🙂

Michael

Advertisment to support michlstechblog.info

One thought on “Linux: Creating a ssh keypair with puttygen”

Leave a Reply

Your email address will not be published. Required fields are marked *

Time limit is exhausted. Please reload CAPTCHA.