Adding a putty .ppk key to MacOS SSH terminal.

por | 22 septiembre, 2020

Converting .ppk key to .pem key on a Mac

macOS by default doesn’t recognize .ppk files, so for that, we need to convert it into a .pem file. It can be done easily via homebrew & putty. 

Install Homebrew

if you are booting into a fresh version of macOS there is a fair chance that homebrew isn’t installed on your Mac. To install homebrew open terminal and paste this comment and press enter. 

/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

PowerShell

Install Putty

Now, We need to install putty your machine. to do that type the following code in the terminal. 

brew install putty

PowerShell

Generate/convert the key

First, we need to mount the folder where keys are saved in the terminal, for that you can type cd then type the path of the folder. alternatively, you can drag the folder to the terminal icon on the dock it will open in a new window.

Then type the following code in the terminal- 

puttygen key.ppk -O private-openssh -o key.pem

PowerShell

replace the key.ppk with the original file name and key.pem with your output file name.

Fixing permission of the file. 

Now if you will try to add the key to ssh, it will show an error like this.

arnabmohapatra@Arnabs-iMac key % ssh-add /Users/arnabmohapatra/Key/arnab_demo.pem @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ @         WARNING: UNPROTECTED PRIVATE KEY FILE!          @ @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ Permissions 0644 for '/Users/arnabmohapatra/Key/arnab_demo.pem' are too open. It is required that your private key files are NOT accessible by others. This private key will be ignored.

PowerShell

This is because the permission of the output file is 0644, which is bad because it is accessible to all the users in the system, which defeats the purpose. Private keys should only be accessible to one user. To fix the permission run the following command. 

chmod 400 /path/to/your/keyfile/key.pem

PowerShell

Adding the key to the terminal. 

To add the key to the terminal run this code. you are should be good to go.

ssh-add /path/to/your/keyfile/key.pem