When attempting SSH authentication using a Putty-generated private key (.ppk file) on Linux systems, you'll encounter the "invalid format" error because OpenSSH doesn't natively support Putty's proprietary key format. This occurs even when the same key works perfectly in Putty clients.
The solution involves converting the .ppk file to OpenSSH-compatible format using puttygen
. Here's how:
sudo apt-get install putty-tools
puttygen privkey.ppk -O private-openssh -o id_rsa
chmod 600 id_rsa
ssh -i id_rsa root@ip
If you don't have puttygen installed, you can use online conversion tools (not recommended for sensitive keys) or convert through Windows Puttygen:
1. Open Puttygen
2. Load your .ppk file
3. Go to Conversions → Export OpenSSH key
4. Save as id_rsa (no extension)
Putty keys (.ppk) differ from OpenSSH keys in:
- Header format (PuTTY-User-Key-File vs BEGIN RSA PRIVATE KEY)
- Encryption schemes
- Metadata storage
If conversion fails, check:
file privkey.ppk # Verify it's actually a Putty key
puttygen --version # Check compatibility
For Ansible configurations, update your inventory file:
[webservers]
server1 ansible_host=192.168.1.1 ansible_user=root ansible_ssh_private_key_file=~/.ssh/id_rsa
After conversion:
- Delete temporary conversion files
- Set proper permissions (600 for private keys)
- Consider using ssh-agent for key management
When attempting to SSH into a remote server using a private key with the command:
ssh -i privkey.ppk root@ip
You encounter the error:
Load key "privkey.ppk": invalid format
root@ip: Permission denied (publickey).
This occurs because the native OpenSSH client doesn't support PuTTY's proprietary .ppk key format.
PuTTY uses its own key format (.ppk) which differs from OpenSSH's native format. While PuTTY, Termius, and other GUI clients can handle .ppk files, the standard OpenSSH client requires keys in PEM format.
The solution is to convert your .ppk file to a format that OpenSSH can understand. You'll need PuTTYgen for this conversion:
On Windows (using PuTTYgen)
1. Open PuTTYgen
2. Click "Load" and select your privkey.ppk
3. Go to Conversions → Export OpenSSH key
4. Save as id_rsa (or any filename without .ppk extension)
On Linux (using putty-tools)
First install the necessary tools:
sudo apt-get install putty-tools
Then convert the key:
puttygen privkey.ppk -O private-openssh -o id_rsa
After conversion, ensure proper file permissions:
chmod 600 id_rsa
Now try connecting with the converted key:
ssh -i id_rsa root@ip
If you frequently need to use PuTTY keys with OpenSSH, consider using ssh-agent:
eval $(ssh-agent)
ssh-add privkey.ppk # After conversion
ssh root@ip
For Ansible configurations, specify the converted key in your inventory:
[webservers]
server1 ansible_host=ip ansible_user=root ansible_ssh_private_key_file=~/.ssh/id_rsa
- Always keep backups of your original .ppk files
- Store converted keys in ~/.ssh/ directory
- Use passphrase protection for additional security
- Consider using ssh-keygen for generating new keys in OpenSSH format