Convert ppk key to pem on Mac
If you’re using a .ppk (PuTTY Private Key) on macOS, you’ll often need to convert it to the OpenSSH .pem format before using it with SSH, Git, Ansible, or cloud servers.
Prerequisites
Install PuTTY (which includes puttygen) using Homebrew:
brew install putty
Verify the installation:
puttygen --version
Convert PPK to PEM
Run the following command:
puttygen private-key.ppk -O private-openssh -o private-key.pem
Example:
puttygen myserver.ppk -O private-openssh -o myserver.pem
If the .ppk file is protected with a passphrase, puttygen will prompt you to enter it during the conversion.
Set Correct Permissions
Secure the PEM file before using it:
chmod 400 myserver.pem
or
chmod 600 myserver.pem
Connect Using SSH
Use the converted key to connect to your server:
ssh -i myserver.pem ubuntu@your-server-ip
Example:
ssh -i myserver.pem ubuntu@192.168.1.100
Verify the PEM Key
Check that the converted key is valid:
ssh-keygen -lf myserver.pem
Troubleshooting
puttygen: command not found
Install PuTTY:
brew install putty
If Homebrew is not installed:
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)" brew install putty
Permission Denied
Ensure the key permissions are restricted:
chmod 400 myserver.pem
Invalid PPK File
Verify that the file is a valid PuTTY private key and has not been corrupted.
Summary
| Task | Command |
|---|---|
| Install PuTTY | brew install putty |
| Convert PPK to PEM | puttygen myserver.ppk -O private-openssh -o myserver.pem |
| Set Permissions | chmod 400 myserver.pem |
| SSH Login | ssh -i myserver.pem user@server-ip |
Conclusion
Converting a .ppk file to a .pem file on macOS is straightforward using puttygen. Once converted, the PEM key can be used with OpenSSH, Git, Ansible, AWS EC2, DigitalOcean, and other Linux servers without requiring PuTTY.
