Openssh Private Key to RSA Private Key - bash

(I am using MAC)
My id_rsa starts with
-----BEGIN OPENSSH PRIVATE KEY-----
but I expect it to starts with
-----BEGIN RSA PRIVATE KEY-----
I have send my id_rsa.pub to server administrator to get the access to server, so I don't want to generate a new key.
Is there any way that I can transfer my id_rsa which is a openssh private key to a RSA private key? (command please.)
If I can transfer, do I also need to transfer id_rsa.pub? (command please.) It seems id_rsa.pub doesn't have a header like id_rsa, so I am not sure if I should also transfer this.

You have an OpenSSH format key and want a PEM format key. It is not intuitive to me, but the suggested way to convert is by changing the password for the key and writing it in a different format at the same time.
The command looks like this:
ssh-keygen -p -N "" -m pem -f /path/to/key
It will change the file in place, so make a backup of your current key just in case. -N "" will set the passphrase as none. I haven't tested this with a passphrase.
The public key should be fine as is.
For full explanation of the above command, see the -m option here: https://man.openbsd.org/ssh-keygen#m

Here's what worked for me for an in-place conversion of a key with a passphrase:
ssh-keygen -p -P "old passphrase" -N "new passphrase" -m pem -f path/to/key

Install and open puttygen
Click on "Load an existing private key file"
Click on menu item "Conversions" -> "Export OpenSSH key"
Save file

You can achieve this easily if you can get your hands on a linux system. I am using ubuntu 18.04 and did the following:
update packages: sudo apt update
install putty: sudo apt install putty
install puttygen: sudo apt install putty-tools
convert the private key to the intermediate format SSHv2: puttygen yourkey -O private-sshcom -o newkey
convert it back to RSA/PEM: ssh-keygen -i -f newkey > newkey_in_right_format
And you are good to go

Some of the answers above didn't work and I actually ran into yet another problem when trying to create a RSA private key from the OpenSSH private key using ssh-keygen command: unsupported cipher 3des-cbc. A helpful gist for that problem can be found here: https://gist.github.com/twelve17/0449491d86158960fdb630160799ff23.
The following command worked for me to create a valid and working RSA private key from a (Putty on Windows generated) OpenSSH key using:
$ sudo apt install putty-tools
$ puttygen existing_key.ppk -o id_rsa -O private-openssh
# enter passphrase if needed

Related

Git Bash - ssh-keygen not working (quits before generating RSA key pair)

It's working fine with Eclipse default git extension and I can do each and every operation using it, I can even generate RSA key.
But when I access git remote using git bash, I got this error:
The authenticity of host '[hostname]:PORT ([IP Address]:PORT)' can't be established.
RSA key fingerprint is SHA256:U...M.
Are you sure you want to continue connecting (yes/no)? fatal: Could not read from remote repository.
Please make sure you have the correct access rights and the repository exists.
and then I removed existing RSA key and tried to generate new RSA key pair and its starts and then quits before completion.
ssh-keygen
Generating public/private rsa key pair.
Enter file in which to save the key (/c/Users/userName/.ssh/id_rsa):
userName#example MINGW64 ~/git/path (branch name):
And I also tried to generate a new RSA key using GIT GUI, I got below error
error writing "stdout": broken pipe
error writing "stdout": broken pipe
while executing
"puts $::answer"
(procedure "finish" line 9)
invoked from within
"finish"
invoked from within
".b.ok invoke"
("uplevel" body line 1)
Thanks in advance.
If you are using a recent version of Git (2.19.2 or more), make sure to generate a PEM private SSH key, not an OPENSSH one.
See "Jenkins: what is the correct format for private key in Credentials"
Use:
ssh-keygen -m PEM -t rsa -P "" -f afile
Then try again your git push, from a simple CMD (no need for bash), using a simplified PATH:
set PATH=C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\
set GH=C:\path\to\git
set PATH=%GH%\bin;%GH%\usr\bin;%GH%\mingw64\bin;%PATH%

How to create a .ppk private key file usnig ssh-keygen [duplicate]

Is there a way to convert PEM files to PPK files? (you may guess that Amazon EC2 gives me a PEM file, and I need to use the PPK format for SSH connectivity).
Use PuTTYGen
Creating and Using SSH Keys
Overview
vCloud Express now has the ability to create SSH Keys for Linux servers. This function will allow the user to create multiple custom keys by selecting the "My Account/Key Management" option. Once the key has been created the user will be required to select the desired SSH Key during the “Create Server” process for Linux.
Create and Use SSH Keys
Create keys
Navigate to “My Account”
Select “Key Management”
Create New Key.
During the key creation process you will be prompted to download your private key file in .PEM format. You will not be able to download the private key again as it is not stored in vCloud Express.
The “Default” checkbox is used for the API.
Deploy server and select key
Connect
SSH (Mac/Linux)
Copy .PEM file to the machine from which you are going to connect.
Make sure permissions on .PEM file are appropriate (chmod 600 file.pem)
Connect with ssh command: ssh vcloud#ipaddress –i privkey.pem
Putty (Windows)
Download Putty and puttygen from - here
Use puttygen to convert .PEM file to .PPK file.
Start puttygen and select “Load”
Select your .PEM file.
Putty will convert the .PEM format to .PPK format.
Select “Save Private Key” A passphrase is not required but can be used if additional security is required.
Connect with Putty.
Launch Putty and enter the host IP address. If connecting to the 10.X private address you must first establish an SSL VPN connection.
Navigate to Connection/SSH/Auth
Click “Browse” and select the .PPK file you exported from puttygen.
Click “Open.” When connection comes up enter username (default is vcloud).
Instructions copied from here
I'm rather shocked that this has not been answered since the solution is very simple.
As mentioned in previous posts, you would not want to convert it using C#, but just once. This is easy to do with PuTTYGen.
Download your .pem from AWS
Open PuTTYgen
Click "Load" on the right side about 3/4 down
Set the file type to *.*
Browse to, and Open your .pem file
PuTTY will auto-detect everything it needs, and you just need to click "Save private key" and you can save your ppk key for use with PuTTY
Enjoy!
If you have Linux machine just install puttygen in your system and use use below command to convert the key
pem to ppk use below command:
puttygen keyname -o keyname.ppk
Below command is use to convert ppk to pem not pem to ppk
puttygen filename.ppk -O private-openssh -o filename.pem
Download puttygen
Then open puttygen
click load
Set the file type to . all files
Save PrivateKey
and then u can just save any name that file became an ppk file
To SSH connectivity to AWS EC2 instance, You don't need to convert the .PEM file to PPK file even on windows machine, Simple SSH using 'git bash' tool. No need to download and convert these softwares - Hope this will save your time of downloading and converting keys and get you more time on EC2 things.
Convert .pem file to .ppk for Windows 10
You need to do following:
1. Download PuTTYGen with Pageant.
2. Press "load" button and select your ".pem" file.
3. Press "save private key" button and save your ".ppk" file.
4. Open Pageant and press "add key" button. Just all. Keep running Pageant in background.
5. Now login through SSH or SFTP without selecting password field.
Save YourPEMFILE.pem to your .ssh directory
Run puttygen from Command Prompt
a. Click “Load” button to “Load an existing private key file”
b. Change the file filter to “All Files (.)
c. Select the YourPEMFILE.pem
d. Click Open
e. Puttygen shows a notice saying that it Successfully imported foreign key. Click OK.
f. Click “Save private key” button
g. When asked if you are sure that you want to save without a passphrase entered, answer “Yes”.
h. Enter the file name YourPEMFILE.ppk
i. Click “Save”
PuTTYgen for Ubuntu/Linux and PEM to PPK
sudo apt install putty-tools
puttygen -t rsa -b 2048 -C "user#host" -o keyfile.ppk
I used a trial version of ZOC Terminal Emulator and it worked. It readily accepts the Amazon's *.pem files.
The trick is though, that you need to specify "ec2-user" instead of "root" for the username - despite the example shown in the EC2 console, which is wrong! ;-)
sudo yum install putty
sudo apt-get install putty-tools
To convert your .pem file to a .ppk file
sudo puttygen pemKey.pem -o ppkKey.ppk -O private
To convert a .ppk file to a .pem file
sudo puttygen ppkkey.ppk -O private-openssh -o pemkey.pem
I had the same issue with PuttyGen not wanting to import an openSSH private key. I tried everything and what I found out was the old version of PuttyGen did not support importing OpenSSH. Once I downloaded the latest Putty, puttygen then allowed it to import the openssh private key just fine. I now have a hole in the side of my desk for pounding my head against it for the past hour.

Can't ssh to remote repository from command line

I'm trying to connect to a remote repository under a specific IP address.
I received the private key through email and I'm on windows using Putty. The .ppk file is in Pageant.
I also created a GIT_SSH environment variable.
After these steps my personal IP was then listed in the firewall, so I guess I was able to connect.
However, when I use git bash to connect to the server, I get the message "permission denied (public key)".
The commands I used are:
$ ssh [IP]
$ ssh [username]#IP
$ ssh -T [username]#IP
I looked up online exhaustively but with no success so far and I really need to access the repo as soon as possible.
Thanks in advance!
Obrigada :)
Two ways to go about it
Using Pageant directly inside Git Bash
This requires setting the GIT_SSH environment variable to the full path of plink.exe (which is part of the putty suite).
Also, I would highly recommend checking if plink.exe works inside GIT Bash as follows:
Full-path-to-plink.exe -v -P port sshusername#sshserver
Another thing to check is the version of Putty suite that you are using. ( I can dig out the details later but) version 0.60 had a bug due to which processes inside cmd could not access Pageant. I believe the issue was fixed in v 0.62 but feel free to use the latest (v 0.67)
Convert putty key to OpenSSH format
Another possibility is exporting the putty key to the OpenSSH format by using puttygen.exe and the using the exported key directly inside GIT Bash:
Open PuttyGen
Click Load
Load your private key
Go to Conversions->Export OpenSSH and export your private key
Copy your private key to ~/.ssh/id_dsa (or id_rsa).
Create the RFC 4716 version of the public key using ssh-keygen
ssh-keygen -e -f ~/.ssh/id_dsa > ~/.ssh/id_dsa_com.pub
Convert the RFC 4716 version of the public key to the OpenSSH format:
ssh-keygen -i -f ~/.ssh/id_dsa_com.pub > ~/.ssh/id_dsa.pub
Then you can do something like this in GIT Bash to test the ssh connectivity:
GIT_SSH=ssh
ssh -v sshusername#sshserver -i ~/.ssh/id_rsa

Generate SSH key on windows via command to specify email address

I have generated my keys using PuttyGen but need to be able to specify exactly the email address used with the following command but this doesn't work as I get an 'is not recognized as an internal or external command error'
ssh-keygen -t rsa -C "joebloggs#mycompany.com"
Can anyone assist in running this command on Windows 10?
You can use PuTTYgen to generate a key with those settings.
For the key type -t rsa you have to select SSH-2 RSA
and for the email / comment -C "joebloggs#mycompany.com" you have to set the Key comment field to joebloggs#mycompany.com
After clicking Generate your can get your public key from the Public key for pasting into OpenSSH authorized_keys file field (this is the same as id_rsa.pub when generated with ssh-keygen)
If you also need the private key to be saved in OpenSSH format just go to Conversions > Export OpenSSH key (this is the same as id_rsa when generated with ssh-keygen)

ssh-keygen error: Passphrase is too short

I was trying to install hadoop on my system in which I need to configure SSH to access to localhost. But while generating the keygen using the command
ssh-keygen -t rsa -P --
But while generating this keygen I got the following error
anamika#Alex:/home/alex$ cd
anamika#Alex:~$ ssh-keygen -t rsa -P --
Generating public/private rsa key pair.
Enter file in which to save the key (/home/anamika/.ssh/id_rsa):
Created directory '/home/anamika/.ssh'.
Saving key "/home/anamika/.ssh/id_rsa" failed: passphrase is too short(minimum five characters)
anamika#Alex:~$ exit
alex#Alex:~$
What is passphrase here? Also I tried to give some file name to save the key but still it didn't work.
Looks like you are mistakenly writing hyphen in place of double quotes in the second line:
anamika#Alex:~$ ssh-keygen -t rsa -P --
replace the above with the following
anamika#Alex:~$ ssh-keygen -t rsa -P ""

Resources