1. Overview
In this tutorial, we’ll be looking at how to convert a key from .pem to .ppk format in Linux.
2. Differences Between .pem Format and .ppk Format
The .pem and .ppk formats are similar in that both of them store the private key information of asymmetric key pairs. The difference between them, however, is the way the private key is stored in the file. Additionally, the .ppk format is only understood by the PuTTY program, whereas other SSH clients generally require the keys to be in the .pem format.
Let’s look at an example. For the same key id_rsa, the .pem format encodes the data in Base64 and includes a distinctive header and footer:
-----BEGIN RSA PRIVATE KEY-----
MIIEowIBAAKCAQEA5PbahU03k1oKf+SJVqQ+Fy5fdeMdK+iTKL08UzQbHfatIt5Y
E0vctW6+/BMvuSeLWLzD3N8UZAC4aVsDetwHPVo+dKNCmuSG4jmQbk5i6wDxu7FI
jc8tCcRotAYQpUV1SJ19hiiruDEDMdZwPEOo67ZpVoPpPpjZLamt820S+mYG/VVf
m6a2AOrPDBuVVkIzViXJTCUzDzmgPS0za8cOOhlbEwzz2NXbVo0g8+iYUTXElpGe
+bVTj5kWwDg+G3D5PPPwzzPYImfIZr4iQHaNGMHWY9TAFx3RBJ/MkWx5gAdJRwTA
1Zef7qJCm0FzBnqkrSpPnGCfqNUpgozGQRDFYQIDAQABAoIBAQC9PcZ4/MxdbsNU
13gn81IaaMqfrhpTS0QuHNI6Vsu+5T5OnoUfVclS7/jMcbM1Dpkeu84KxRqeWPYS
phXnOuqE7AzI7JNFYHKXkkps0T7yy3IA1tOH2d94vixn9sdVQmZgoUK5Wu4rK99f
FsTnGmkIgVjpF9f1U/HUyvSqSNGxwIf6L9xd7XHc/EDSdXbGcJipbknDZqgSyYFS
xC5F6d5lrCDZPgfGCUJhF2qJ9AsXehUtlKYbufJ9EWzMr3M5auk8IFFTIUY7DcrO
7mnjIOHY1PndaoOMf20t0uTeJxm1b3KqRUbXHPmyCUcvBuFNnvBf7Y6VvweBZeO1
qWriysZNAoGBAPKpDVvXcVK6LQn+0yU3H6YNUryTHzwpfL2nrrWBepHY090WRARs
IBhqHzCQwqUxkiHoMcOOvyOImnI6gdUglhfRA2I5tOuKf+MXbMAQoed6leUMEiWC
ozYDQowDnPV/28V0Jj/+09YMVAAE8WnqQZVE6qkoS1vIJFh+kv0rp1jDAoGBAPGN
Dpgq8ijforatJvifPB1yAN0kP2ThtpIKQV+YwOhiL5MbU2CnH+/Da/0mm8pqPrcm
zm5VFYyVa+4hlWwSSCGcl69ON+EfHFeaX1hqViDyixOLPqouThFpmAhNqvR5pRM6
1uX+vAiwfhLB4LSXMNdq3gLCCZ+ehLKU1x3kmOcLAoGALAGGX6pxbaw/sLlatzwI
7EcsQvB3UKTBb29yWo4xmTN2MHjyOs8U/vh30YnfErArrSR7qdhAR4RlZePAWdNA
BO+tqmmGqtSCHr/HxAkAI4dymYgX3l+Tk58BuXyKQWc/hs5qhV6EMiQoM5yx3yBR
Zm2KFMUu7WUdWkMSCwGYppsCgYBUJR1GaP9+uZkHJf6DcYURhNtELhJfZDmjWis3
0BCzYzDLgCNlchKwBVWjFEYFF0nNp5kV2lHtbUfx5oUU5rF19ATrLsZMh/fplH9O
X4ytYZCNOF6WDhdn/W7WxaeeDpowvriJ2llKdaEVi7BpeJmtES9RqqKLlj8Hrs3Z
Pf79zQKBgCc91dTZ3fJAH6Ms8tN9ZYWWIN5sTXXPa1WNu0e4c49M+oKwmkH7suk6
qLgzaWTTakTdA9idTcHkaTCDqH5t/7FiqRH8U7mwwzsosN9gpAC7OAVT9+fDUWqj
R29Gu/+khG+NutEWURNh7uCFLL08xkIjGcROHKQ+xl1vH9b5QXQV
-----END RSA PRIVATE KEY-----
On the other hand, here’s how the .ppk format stores the same key:
$ PuTTY-User-Key-File-2: ssh-rsa
Encryption: none
Comment: imported-openssh-key
Public-Lines: 6
AAAAB3NzaC1yc2EAAAADAQABAAABAQDk9tqFTTeTWgp/5IlWpD4XLl914x0r6JMo
vTxTNBsd9q0i3lgTS9y1br78Ey+5J4tYvMPc3xRkALhpWwN63Ac9Wj50o0Ka5Ibi
OZBuTmLrAPG7sUiNzy0JxGi0BhClRXVInX2GKKu4MQMx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u4IUsvTzGQiMZxE4cpD7GXW8f1vlBdBU=
Private-MAC: 078893967d499e1561f90460a73b2879916a3dc5
Because the contents are similar, it’s easy to convert one format into another with the help of command-line tools like puttygen. Let’s look at how we can convert our .pem key to a .ppk for use with PuTTY.
3. Converting Keys Into .ppk Format Using puttygen
PuTTYgen is a command line tool for generating SSH key pairs. Additionally, it also allows us to convert the key pairs into different formats.
3.1. Installing puttygen
To obtain the binary, we have to install the putty-tools package on our system. Depending on the Linux distribution, we can install the software using the package manager of the system. For example, we’ll use apt-get in Ubuntu Linux:
$ sudo apt-get update
$ sudo apt-get install -y putty-tools
Once the installation completes without error, we can verify the installation:
$ puttygen --version
puttygen: Release 0.73
Build platform: 64-bit Unix
Compiler: gcc 9.3.0
Source commit: 745ed3ad3beaf52fc623827e770b3a068b238dd5
3.2. Converting .pem File to .ppk
To convert a .pem key file into .ppk format, we can use the -O option with the private or public argument, depending on the type of keys we want to convert.
For example, let’s convert an existing id_rsa.pem into its corresponding .ppk file:
$ puttygen id_rsa.pem -O private -o id_rsa_private.ppk
The command above extracts the private key from id_rsa.pem and saves it in the .ppk format in the id_rsa_private.ppk file.
Conversely, to obtain the public key, we use the public argument on the -O option:
$ puttygen id_rsa.pem -O public -o id_rsa_public.ppk
4. Conclusion
In this tutorial, we first learned that the .pem and .ppk key formats store private keys differently. Then, we introduced the puttygen tool along with basic installation information. Finally, we’ve demonstrated the command for converting the .pem file into its corresponding .ppk file.