Skip to content

Instantly share code, notes, and snippets.

@myh-st
Forked from rxm/sshPemKey.md
Last active October 30, 2020 04:30
Show Gist options
  • Save myh-st/5917eddc7238591673e5f0f701b92b1a to your computer and use it in GitHub Desktop.
Save myh-st/5917eddc7238591673e5f0f701b92b1a to your computer and use it in GitHub Desktop.
Create an SSH key in PEM format

Create an SSH key in PEM format

I have not been able to use ssh-keygen -e to reliably generate a private key for SSH in PEM format. This format is sometimes used by commercial products. Instead, I had to convert the key using openssl.

# generate an RSA key of size 2048 bits
ssh-keygen -t rsa -b 2048 -f azure -C 'azure-dev'

# copy key to x.x.x.x and add to authorized_keys

# convert private key to PEM format
openssl rsa -in azure -outform PEM -out azure.pem
chmod 700 azure.pem

# test key
ssh -i ./azure.pem [email protected] -p 22

# add a passphrase
ssh-keygen -p -f azure.pem

# does it have a passphrase
ssh-keygen -y -f azure.pem

# test key, now with passphrase
ssh -i ./azure.pem [email protected] -p 22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment