Table of Contents
Convert OpenSSH Private Key to RSA Private Key
In some cases, you want to convert OpenSSH private key to RSA private key. An OpenSSH private key begin with: —–BEGIN OPENSSH PRIVATE KEY—–
You can check if you’ve an OpenSSH private key in PowerShell with Get-Content cmdlet.
Get-Content D:\SSH\openssh-privkey
-----BEGIN OPENSSH PRIVATE KEY-----
b3BlbnNzaC1rZXktdjEAAAAABG5vbmUAAAAEbm9uZQAAAAAAAAABAAABFwAAAAdz
c2gtcnNhAAAAAwEAAQAAAQEA3kQeE0v2hu7gdv0FNWrlYoGel4oPkoE0L6wPPTFc
...
-----END OPENSSH PRIVATE KEY-----
1. Open PowerShell as administrator then create a folder named .ssh in the home directory of the current logon user.
New-Item ~/.ssh -Type Directory
2. Copy the OpenSSH private key to that folder then rename it. The RSA private key stores in PEM format (.pem).
Copy-Item 'D:\SSH\openssh-privkey' 'C:\Users\admin\.ssh\rsa-privkey.pem'
3. Now, run the below command to convert OpenSSH private key to RSA private key.
ssh-keygen -p -m PEM -f 'C:\Users\admin\.ssh\rsa-privkey.pem'
If you want to protect your private key by a pass phrase, type it when prompted. In our case, we just press Enter to continue without adding the pass phrase.
Enter new passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved with the new passphrase.
4. The OpenSSH private key is converted to RSA private key. You can check it using the Get-Content cmdlet.
Get-Content 'C:\Users\admin\.ssh\rsa-privkey.pem'
-----BEGIN RSA PRIVATE KEY-----
MIIEowIBAAKCAQEA3kQeE0v2hu7gdv0FNWrlYoGel4oPkoE0L6wPPTFcNGpp+EaG
8JqOQEDSjNEZl0xZcNtQHq0Q1EsOjYq6P3ZMnRuawTt9+Rpz88ZFB0NG+zJ4xqoU
...
-----END RSA PRIVATE KEY-----
Using an OpenSSH client, we can use both of private key types to SSH to the remote Linux system with key-based authentication.
ssh [email protected] -i ~\.ssh\openssh-privkey
ssh [email protected] -i ~\.ssh\rsa-privkey.pem
Using the PuTTY Key Generator
Alternatively, we can use the PuTTY Key Generator to convert RSA private key to OpenSSH private key. Download the PuTTYGen from the official site then open it.
1. In the PuTTYGen, navigate to File → Load private key.
2. Load the OpenSSH private key. If you cannot see the key in the folder, change the file type to All Files.
3. Click OK to continue.
4. Now, navigate to Conversions → Export OpenSSH key
5. Enter a desire name with .pem extension.
Finally, open the converted file using any text editor to verify it works. The file should begin with —–BEGIN RSA PRIVATE KEY—–
Not a reader? Watch this related video tutorial: