How do I save an openssh privatekey to a file? - windows-server-2008

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.

Related

Can't connect to SFTP (with private key file) in Copy Data Tool

I am trying to copy data from SFTP to blob but got stuck when creating SFTP source.
I have the connection details and can easily connect on Filezilla or WinSCP. However, I am unable to get it to work in Azure data factory.
I am not using code but the user interface.
The connection details on the page creating the SFTP source:
Connect via integration runtime: AutoResolveIntegrationRuntime (default)
Host: xyz
Port: 22 (can't remove it as it doesn't like it)
SSH Host Key Validation: Enable SSH Host Key Validation
SSH Host Key Finger-print: taken from WinSCP - Session - Server/protocol information
Authentication type: SSH Public Key Authentication -can't use basic as the private key holds the security info
User name:XXX
Private Key Type: Use Key Content
Private key content: loaded the .ppk file, tried also tried loading the .pem file and got different errors
Pass Phrase: none
When setting up this sftp in WinSCP or FileZilla it automatically converted the provided .pem file into .ppk.
When I loaded the .ppk file into ADF I got an error: Invalid Sftp credential provided for 'SshPublicKey' authentication type.
When I loaded the .pem file I got: Meet network issue when connect to Sftp server 'spiderftp.firstgroup.com', SocketErrorCode: 'TimedOut'.
I have also tried 'Disable SSH Host Key Validation' in SSH Host Key Validation and made no difference.
I have also opened the .ppk file in PuttyGen and used that host key finger print and still no luck.
Only getting these 2 errors depending on which file I load.
Can't find anything about this online so would be grateful for some advice.
Have you read this note in this doc?
https://learn.microsoft.com/en-us/azure/data-factory/connector-sftp#using-ssh-public-key-authentication
SFTP connector supports RSA/DSA OpenSSH key. Make sure your key file content starts with "-----BEGIN [RSA/DSA] PRIVATE KEY-----". If the private key file is a ppk-format file, please use Putty tool to convert from .ppk to OpenSSH format.
Got this working today. Like you, could connect using WinSCP and failed when using ADF.
The link Fang Liu shared contains our answers, but my issue was not the private key. I suspect Fang's suggestion resolved your problem and I'm sharing my answer here to help others who may encounter similar.
My issue:
When using Private Key Authentication in ADF the password becomes a Pass Phrase and you no longer have the ability to supply a password. To overcome the problem we disabled password authentication for the user and the SFTP connection started working.
As stated in the documentation. The Pass Phrase is used to decrypt the private key if it is encrypted.
Also worth noting:
If you store the contents of the private key in Key Vault you need
to base64 encode the entire contents of the exported key and use
that string. This includes "-----BEGIN RSA PRIVATE KEY-----" and the
end. The same applies if you want to paste the value into the
textbox of the SFTP linked service edit screen.
I did not try to manually edit the JSON of the Linked Service to explicitly provide a password and this could be workaround for someone to test if they are unable to disable the password.
I used PuTTYGen to export the PPK to a private key and had the same fingerprint issue too so I just disabled cert validation. Funnily you can use the fingerprint provided by the error and it passes validation so not sure where the bug lies. :-)

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.

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

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);

Where in a PEM (SSL) file is the passphrase stored? If you open a .pem file in a text editor, can you steal the passphrase?

I'm trying to understand how a .pem file is laid out. How is the passphrase authenticated? How does the .pem file check against itself the passphrase you try to open it with?
Multiple different kinds of data are stored in files with the extension .pem. So your question is imprecise. But suppose it is a password-protected private key file. Why do you believe the password is stored anywhere in it? In fact it is not stored in the file. The passphrase is used to generate a symmetric key, which is used to decrypt the file and check the decrypted file for consistency.

where can I find SSL certificates on Mac OSX

I need an access to .k12 or .pem files for all https websites I am visiting on Mac OSx machine. Can anyone help me know the path where these files can be found.
Also, need to know a way to decrypt some packets using the key.
There are a couple of ways to get a certificate file in OSX. One way is to export the certificates from Keychain Access. Select Certificates in the Category (lower left) panel, choose Select All from the Edit menu (or hit ⌘A), and then choose Export Items... from the File menu (or hit ⇧⌘E). You can export your certificates as a .p12 file or a .cer file. The problem with this approach is you have to perform these steps periodically to keep your file in sync with the latest updates from Apple.
Another way is to install OpenSSL and use the cert.pem file that comes with it. Similarly, you'll have to keep OpenSSL up to date.
You would simply access the tool named "Keychain Access" in the Utilities folder of your Applications directory.
Once there, you can filter each keychain to only show certificates.
As for decrypting packets using a given key, there are plenty functions doing that within the Security framework, but this question would require clarification (Language requirement etc).
I was looking for this too. I couldn't find the files anywhere so I thought how about exporting them.
From the Keychain Access:
On left pane, click on the KEYS. On right pane, CTRL-Click on the desired certificate.
The Public key should be exported as a PEM file.
The Private Key should be exported as a P12 file.
The Certificate should be exported as a CRT file.
The Private key export option will as for a passphrase and then the user's keychain password. Upon import you will be asked for this passphrase.
NOTE: The private key, contains the public key.