Skip to content

Instantly share code, notes, and snippets.

@zircote
Created September 26, 2011 21:45
Show Gist options
  • Star 69 You must be signed in to star a gist
  • Fork 15 You must be signed in to fork a gist
  • Save zircote/1243501 to your computer and use it in GitHub Desktop.
Save zircote/1243501 to your computer and use it in GitHub Desktop.
Convert a AWS PEM into a ssh pub key
ssh-keygen -y -f private_key1.pem > public_key1.pub
@kennblvnp
Copy link

Ill try this

@kennblvnp
Copy link

It works. Thanks!

@acceptableEngineering
Copy link

Works, and not over-engineered like other solutions found online today. Thanks!

@jasonm0928
Copy link

Nice, thanks.

@kushalgangan
Copy link

kushalgangan commented Feb 14, 2019

Thanks 👍

@maffan91
Copy link

Thanks.

@scheung38
Copy link

the private and public key names has to match?

$ ssh-keygen -y -f private_key1.pem > public_something_else.pub

@slaughtr
Copy link

@scheung38 they do not

@QuotableWater7
Copy link

Gracias friend

@matthewchung74
Copy link

thanks!

@Faishal24
Copy link

doesn't work, it says "Load key "pubkey.pem": invalid format"

@ricsaka
Copy link

ricsaka commented Dec 15, 2022

doesn't work, it says "Load key "pubkey.pem": invalid format"

It's the same for me. Any ideas anyone?

@pony012
Copy link

pony012 commented May 26, 2023

@Faishal24 , @ricsaka , maybe you need to pass the param -m PKCS8

ssh-keygen -y -f private_key1.pem -m PKCS8 > public_key1.pub 

From the manual:

 -m key_format
        Specify a key format for the -i (import) or -e (export) conversion options.  The
        supported key formats are: “RFC4716” (RFC 4716/SSH2 public or private key), “PKCS8”
        (PEM PKCS8 public key) or “PEM” (PEM public key).  The default conversion format is
        “RFC4716”.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment