Convert .pem key file to .ppk in Windows automatically/script/command line - ssh

I'm using Vagrant to create VMs on a Windows host, to which I would like to connect with PuTTY. Vagrant creates an RSA private key in the .pem format. PuTTY needs a key in the .ppk format to create a connection.
I would like to convert the .pem to .ppk automatically when creating the vagrant VM.
The question of how to convert .pem to .ppk has been asked and answered lots of times, but on Windows all those answers involve clicking through the puttygen GUI. It seems that on Linux, puttygen can be operated entirely from the command line, but on Windows the GUI must be used.
Having to click through a GUI is a slow point in my workflow when creating new VMs that I would like to avoid.
Is there any command-line/scriptable/programmatic way of converting .pem files to .ppk format on Windows?

WinSCP supports command-line conversion of private keys from the OpenSSH (or ssh.com) format to the PuTTY .ppk format.
Use the /keygen switch:
winscp.com /keygen mykey.pem /output=mykey.ppk
(I'm the author of WinSCP)
Or, you can compile/run Unix command-line puttygen using Cygwin.
Or build your own tool from PuTTY code, it's open-source. It is rather easy (that's basically what WinSCP does).
Use import_ssh2 to load the .pem:
ssh2_userkey *import_ssh2(const Filename *filename, int type,
char *passphrase, const char **errmsg_p);
Use ssh2_save_userkey to save it as .ppk:
bool ssh2_save_userkey(
const Filename *filename, ssh2_userkey *key, char *passphrase);

Related

How do I save an openssh privatekey to a file?

My colleague send me an openssh privatekey so I can import it into putty so that I have the access of windows server, I don't know how to save it into a file, because I need to copy it first.

PuTTY - Unable to use key file (not a private key)

I have a PPK file and I am trying to have PuTTY use it, when I am connecting to a remote server. But I keep getting this error below, and then I am just asked for my username (while I should be directly allowed in as root).
I don't understand what the problem is, and what's worse I have no idea how to troubleshoot further. A colleague of mine is using the same file and says everything is OK on his side. So I am stuck.
I did a web search and all I find is recommendations to convert the PEM file into a PPK file. But that does not apply in my case, I already have a PPK file.
I am using Windows on my local machine and the PPK file is located in C:\ssh-keys\
Unable to use key file "C:\ssh-keys\filename.ppk" (not a private key)
login as:
Here is the header:
filename.ppk
ё : mBIN ‚Ѓ& PuTTY-User-Key-File-2: ssh-rsa
Encryption: none
Comment: imported-openssh-key
Public-Lines: 6
Your key file is corrupted.
A .ppk file must start with the PuTTY-User-Key-File- followed by the ppk format version number. It must be a plain text file. No binary data. No UTF BOM. Your colleague must have a different (correct) copy of the file.

Generate valid openssh ssh key under windows

I've some persons that are under windows, and they need a public/private RSA keys pair in order to get them authenticated to gistosis, a GIT server. We use SmartGit as our GIT GUI, and this tool require the private key to be in the format of OpenSSH.
Using puttyGen, I've been able to get a openssh public key, that is printed in the window, but not a private key. I can only save a private key using the Save button, and it save a format that is not like the one we have using the *nix tool.
How can we use windows tool in order to generate a VALID openssh compatible public and private key ?
Thanks.
puttygen has a menu: Conversion -> Export OpenSSH Key That will save the private key to the openssh format.

Can linux ssh private key files be used unchanged in putty on Windows?

I have been connecting to my site from a Mac using ssh. My Mac is dead. Now I have my key files but need to use Putty on Windows...
1 - Can I take my id_rsa file and rename it as private.ppk and use it as-is with Putty?
2 - Are there any gotchas? - because the remote server is refusing my keys. :(
You can't use OpenSSH keys directly with PuTTY, but if you have the puttygen tool (by the author of PuTTY), you can import them.
For directions, see the following from the PuTTY documentation: http://the.earth.li/~sgtatham/putty/0.60/htmldoc/Chapter8.html#puttygen-conversions
No, you need to convert them first using puttygen

Can I use SSH keys in something other than PuTTy (on Mac)?

Bluehost only recommends PuTTy. However, is it possible to use ssh keys without any extra, visible programs in Mac?
I would like to have a connection to my server to be a breeze, so that I can control my server in Terminal.
Of course! On Unix and OS X, the ssh-keygen command will generate public and private keys for SSH public-key authentication. The usual way to invoke this command (on the client) is:
ssh-keygen -t rsa
This command will ask you where to place your private key; the default place is ~/.ssh/id_rsa, and the public key will be placed in the file of the same name with a .pub extension added (for example: ~/.ssh/id_rsa.pub). The command also asks you to create a password ("passphrase") for the private key; you can leave it blank for no password as I do, but I don't recommend this practice.
Once you have your public and private keys on the client computer, you need to make your server recognize that public key. If you have shell access to the server, you can upload the public key file with scp, then use ssh to run the following command on the server:
cat id_rsa.pub >> ~/.ssh/authorized_keys
If your hosting company doesn't give you shell access (though Bluehost does), or this procedure doesn't work, it will likely give you a web interface to the same functionality.
Once your server is set up to recognize your public key, it will allow you access without a password when ssh on the client tries to use your private key for authentication. You may still have to enter your private key's password, but typically you only need to do this once for each client login session.
Sure, I do this all the time. Just follow these directions to generate an SSH key and copy it to your server. The instructions should work on both Mac and Linux.
SSHKeychain is pretty much ideal for this. It lives unobtrusively on the menu bar and integrates seamlessly with OS X's Keychain and SSH implementations.
You will need to use ssh-keygen as described in other answers, but once you've done that you can use SSHKeychain to avoid having to type your private key passphrase all the time.
OpenSSH should be available to you on OS X; open a terminal and check out "man ssh". SSH keys get stored (in a format different from PuTTY) in ~/.ssh. Having a config in ~/.ssh/config can make your life easier, too; you'll be able to say "Use this $SHORTNAME for this $HOST using this $KEY" and similar.
At the terminal prompt do
$ apropos ssh
You should get a list of all the programs Mac OS X comes with related to ssh.
Using the ssh* tools, your ssh keys will be stored under ~/.ssh. PuTTY is nice, but compared to the standard OpenSSH tools, it's really only useful on Windows systems.
Sure can! First run:
ssh-keygen
And go through the steps. It is a good idea to give it a password and such. Then you can:
cat ~/.ssh/id_rsa.pub
and copy-paste the result into the bluehost public key textarea.